github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/config/cli.go (about)

     1  package config
     2  
     3  import "github.com/qri-io/jsonschema"
     4  
     5  // CLI defines configuration details for the qri command line client (CLI)
     6  type CLI struct {
     7  	ColorizeOutput bool `json:"colorizeoutput"`
     8  }
     9  
    10  // SetArbitrary is an interface implementation of base/fill/struct in order to safely
    11  // consume config files that have definitions beyond those specified in the struct.
    12  // This simply ignores all additional fields at read time.
    13  func (c *CLI) SetArbitrary(key string, val interface{}) error {
    14  	return nil
    15  }
    16  
    17  // DefaultCLI returns a new default CLI configuration
    18  func DefaultCLI() *CLI {
    19  	return &CLI{
    20  		ColorizeOutput: true,
    21  	}
    22  }
    23  
    24  // Validate validates all fields of cli returning all errors found.
    25  func (c CLI) Validate() error {
    26  	schema := jsonschema.Must(`{
    27      "$schema": "http://json-schema.org/draft-06/schema#",
    28      "title": "CLI",
    29      "description": "Config for the CLI",
    30      "type": "object",
    31      "required": ["colorizeoutput"],
    32      "properties": {
    33        "colorizeoutput": {
    34          "description": "When true, output to the command line will be colorized",
    35          "type": "boolean"
    36        }
    37      }
    38    }`)
    39  	return validate(schema, &c)
    40  }
    41  
    42  // Copy returns a deep copy of a CLI struct
    43  func (c *CLI) Copy() *CLI {
    44  	res := &CLI{
    45  		ColorizeOutput: c.ColorizeOutput,
    46  	}
    47  	return res
    48  }
    49  
    50  // WithPrivateValues returns a deep copy of CLI struct all the privates values of the receiver added to the *CLI param
    51  func (c *CLI) WithPrivateValues(p *CLI) *CLI {
    52  	return p.Copy()
    53  }
    54  
    55  // WithoutPrivateValues returns a deep copy of an CLI struct with all the private values removed
    56  func (c *CLI) WithoutPrivateValues() *CLI {
    57  	return c.Copy()
    58  }