-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add basic validation for cli config
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
package config | ||
|
||
import "github.com/qri-io/jsonschema" | ||
|
||
// CLI defines configuration details for the qri command line client (CLI) | ||
type CLI struct { | ||
ColorizeOutput bool | ||
ColorizeOutput bool `json:"colorizeoutput"` | ||
} | ||
|
||
// Default returns a new default CLI configuration | ||
func (CLI) Default() *CLI { | ||
// DefaultCLI returns a new default CLI configuration | ||
func DefaultCLI() *CLI { | ||
return &CLI{ | ||
ColorizeOutput: true, | ||
} | ||
} | ||
|
||
// Validate validates all fields of cli returning all errors found. | ||
func (c CLI) Validate() error { | ||
schema := jsonschema.Must(`{ | ||
"$schema": "http://json-schema.org/draft-06/schema#", | ||
"title": "CLI", | ||
"description": "Config for the CLI", | ||
"type": "object", | ||
"required": ["colorizeoutput"], | ||
"properties": { | ||
"colorizeoutput": { | ||
"description": "When true, output to the command line will be colorized", | ||
"type": "boolean" | ||
} | ||
} | ||
}`) | ||
return validate(schema, &c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCLIValidate(t *testing.T) { | ||
cliDefault := CLI{ | ||
ColorizeOutput: true, | ||
} | ||
err := cliDefault.Validate() | ||
if err != nil { | ||
t.Errorf("error validating cliDefault: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters