diff --git a/cmd/centry/runtime.go b/cmd/centry/runtime.go index ef63d05..4903acb 100644 --- a/cmd/centry/runtime.go +++ b/cmd/centry/runtime.go @@ -55,7 +55,7 @@ func NewRuntime(inputArgs []string, context *Context) (*Runtime, error) { runtime.cli = &cli.App{ Name: context.manifest.Config.Name, HelpName: context.manifest.Config.Name, - Usage: "A tool for building declarative CLI's over bash scripts, written in go.", // TODO: Set from manifest config + Usage: context.manifest.Config.Description, UsageText: "", Version: context.manifest.Config.Version, diff --git a/cmd/centry/runtime_test.go b/cmd/centry/runtime_test.go index 2e7fa7e..82b5ab7 100644 --- a/cmd/centry/runtime_test.go +++ b/cmd/centry/runtime_test.go @@ -252,6 +252,18 @@ func TestMain(t *testing.T) { g.Describe("output", func() { out := execQuiet("") + + g.It("should display the program name", func() { + expected := `NAME: + centry` + test.AssertStringContains(g, out.Stdout, expected) + }) + + g.It("should display the program description", func() { + expected := "A manifest file used for testing purposes" + test.AssertStringContains(g, out.Stdout, expected) + }) + g.It("should display available commands", func() { expected := `COMMANDS: commandtest Command tests @@ -275,6 +287,16 @@ func TestMain(t *testing.T) { test.AssertStringContains(g, out.Stdout, expected) }) + + g.Describe("default config output", func() { + g.It("should display the default program description", func() { + expected := `NAME: + name - A new cli application` + out := execQuiet("", "test/data/runtime_test_default_config.yaml") + test.AssertNoError(g, out.Error) + test.AssertStringContains(g, out.Stdout, expected) + }) + }) }) g.Describe("command help output", func() { @@ -334,10 +356,11 @@ OPTIONS: out := execQuiet("helptest placeholder --help") test.AssertStringContains(g, out.Stdout, expected) }) + }) - g.Describe("placeholder subcommand help", func() { - g.It("should display full help", func() { - expected := `NAME: + g.Describe("placeholder subcommand help output", func() { + g.It("should display full help", func() { + expected := `NAME: centry helptest placeholder subcommand1 - Description for placeholder subcommand1 USAGE: @@ -347,14 +370,15 @@ OPTIONS: --opt1 value Help text for opt1 --help, -h Show help (default: false)` - out := execQuiet("helptest placeholder subcommand1 --help") - test.AssertStringContains(g, out.Stdout, expected) - }) + out := execQuiet("helptest placeholder subcommand1 --help") + test.AssertStringContains(g, out.Stdout, expected) }) }) }) } +const defaultManifestPath string = "test/data/runtime_test.yaml" + type execResult struct { Source string ExitCode int @@ -363,15 +387,27 @@ type execResult struct { Stderr string } -func execQuiet(source string) *execResult { - return execCentry(source, true) +func execQuiet(source string, params ...string) *execResult { + manifestPath := defaultManifestPath + if len(params) > 0 { + if params[0] != "" { + manifestPath = params[0] + } + } + return execCentry(source, true, manifestPath) } -func execWithLogging(source string) *execResult { - return execCentry(source, false) +func execWithLogging(source string, params ...string) *execResult { + manifestPath := defaultManifestPath + if len(params) > 0 { + if params[0] != "" { + manifestPath = params[0] + } + } + return execCentry(source, false, manifestPath) } -func execCentry(source string, quiet bool) *execResult { +func execCentry(source string, quiet bool, manifestPath string) *execResult { var exitCode int var runtimeErr error @@ -380,7 +416,7 @@ func execCentry(source string, quiet bool) *execResult { source = fmt.Sprintf("--quiet %s", source) } context := NewContext(CLI, io.Headless()) - runtime, err := NewRuntime(strings.Split(fmt.Sprintf("test/data/runtime_test.yaml %s", source), " "), context) + runtime, err := NewRuntime(strings.Split(fmt.Sprintf("%s %s", manifestPath, source), " "), context) if err != nil { exitCode = 1 runtimeErr = err diff --git a/examples/centry/centry.yaml b/examples/centry/centry.yaml index 1d1604d..d0eec04 100644 --- a/examples/centry/centry.yaml +++ b/examples/centry/centry.yaml @@ -72,6 +72,7 @@ options: config: name: centry + description: A tool for building declarative CLI's over bash scripts, written in go version: 1.0.0 log: level: info diff --git a/internal/pkg/config/manifest.go b/internal/pkg/config/manifest.go index 2f4b2b0..887f992 100644 --- a/internal/pkg/config/manifest.go +++ b/internal/pkg/config/manifest.go @@ -54,9 +54,10 @@ func (o Option) Annotation(namespace, key string) (*Annotation, error) { // Config defines the structure for the configuration section type Config struct { - Name string `yaml:"name,omitempty"` - Version string `yaml:"version,omitempty"` - Log LogConfig `yaml:"log,omitempty"` + Name string `yaml:"name,omitempty"` + Description string `yaml:"description,omitempty"` + Version string `yaml:"version,omitempty"` + Log LogConfig `yaml:"log,omitempty"` } // LogConfig defines the structure for log configuration section diff --git a/internal/pkg/config/schema.go b/internal/pkg/config/schema.go index c15375f..2853311 100644 --- a/internal/pkg/config/schema.go +++ b/internal/pkg/config/schema.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -// schemas/manifest.json (1.841kB) +// schemas/manifest.json (1.902kB) package config @@ -69,7 +69,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _schemasManifestJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x95\x51\x6e\xdb\x30\x0c\x86\xdf\x7d\x0a\x41\xdb\xa3\x1b\x63\xaf\x3e\xc3\x6e\x30\x04\x83\x22\xd3\xb6\x3a\x8b\xf4\x28\x39\x6b\x50\xe4\xee\x83\x64\x25\xd3\xdc\x78\xcb\x1c\xac\x4f\x6a\x29\x7e\x14\xc9\xff\x4f\xf2\x5a\x08\x21\x3f\x3a\xdd\x83\x55\xb2\x16\xb2\xf7\x7e\xac\xab\xea\xd9\x11\x3e\xcd\xd1\x1d\x71\x57\xcd\x7f\x7e\x90\x65\x4c\x37\xcd\x25\xd5\xd5\x55\xd5\x19\xdf\x4f\x87\x9d\x26\x5b\x7d\x63\xe3\x3c\xb5\x2d\xb0\xea\x87\xaa\xa3\x27\x0d\xe8\xf9\x94\x70\x57\x59\x85\xa6\x05\xe7\x77\xa1\xbe\x2c\x8b\x50\xcd\x9f\x46\x08\xe5\xe8\xf0\x0c\xda\xcf\x2f\x8c\x4c\x23\xb0\x37\xe0\x64\x2d\x42\x8b\x42\x48\xa7\xd9\x8c\xfe\x57\x20\x43\x15\xb3\x3a\x45\x32\x86\x8d\x07\x9b\xe7\x65\x99\xce\xb3\xc1\x4e\xa6\x8b\x73\x3c\xcf\x33\x28\x35\x59\xab\xb0\x79\xf0\x85\x6c\x8c\x74\x73\x63\x98\x74\x83\xca\x06\xe6\xf5\x4d\x7f\xa5\x90\xd6\xe0\x67\xc0\xce\xf7\xb2\x16\x9f\x2e\x3d\x5e\x2a\xaa\x18\xfe\x67\xae\x87\x61\xdc\xc2\x35\x30\x2f\xdf\x10\x6e\xc1\x15\x22\x79\x15\x68\xf7\x3b\x9e\x76\x95\x74\xc8\xb4\x88\x18\xc3\xf7\xc9\x30\x04\xaf\x7d\x49\xbb\x2a\xd3\xec\x62\x7f\x53\x41\x1a\xaf\x8f\xbc\x8f\x80\x89\xb9\xb9\x11\xc0\xc9\x86\xd6\xb3\xd0\x81\x68\x08\xa7\x83\x21\x3c\xb1\x5f\xec\x69\xab\x1d\x5c\x4f\xec\xef\x02\xc3\xff\xea\x65\xb5\x10\xe0\xf1\xeb\xd6\x26\x1e\xf4\x48\x03\xad\x9a\x86\xfb\xa6\xf8\x1f\xf6\x8a\x4c\x99\x34\x58\xb1\x97\x26\x6c\x4d\x77\xcb\x5d\x0b\xcf\xac\x39\x66\x9b\xc2\xf2\x08\xec\xb6\xac\x55\x0e\xd4\xad\x38\xf6\xad\xcb\xff\xe4\xf3\x50\x0a\x8e\x30\xfc\xd5\xea\x0d\x1c\xa6\x18\x31\xd8\x52\x38\x7f\x28\xc6\x98\xc1\x4c\x3c\x7f\x7c\xd1\xe8\xa5\xf3\xe3\xdb\xd0\x9a\x97\x3b\x47\xcc\xd0\x4c\xdb\x62\xa1\xf1\xca\x17\xc8\x65\x9b\x49\xe4\x80\x45\x64\x91\x7e\xfd\x35\x28\xaf\xc2\x8b\x7d\x71\x2e\x7e\x06\x00\x00\xff\xff\x4a\x7c\xb4\xc0\x31\x07\x00\x00") +var _schemasManifestJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x95\x5d\x92\xd3\x30\x0c\xc7\xdf\x73\x0a\x8f\xe1\x31\xdb\x0c\xaf\x39\x03\x37\x60\x3a\x8c\xeb\x28\x89\x97\x58\x0a\xb2\x53\xb6\xb3\xd3\xbb\x33\x76\xdc\x62\xb2\x0d\x94\x74\xd8\x27\xb7\xb2\x7e\xb2\x3e\xfe\x6a\x5f\x0b\x21\xe4\x47\xa7\x7b\xb0\x4a\xd6\x42\xf6\xde\x8f\x75\x55\x3d\x3b\xc2\xa7\xd9\xba\x23\xee\xaa\xf9\xe3\x07\x59\x46\x77\xd3\x5c\x5c\x5d\x5d\x55\x9d\xf1\xfd\x74\xd8\x69\xb2\xd5\x37\x36\xce\x53\xdb\x02\xab\x7e\xa8\x3a\x7a\xd2\x80\x9e\x4f\x09\x77\x95\x55\x68\x5a\x70\x7e\x17\xe2\xcb\xb2\x08\xd1\xfc\x69\x84\x10\x8e\x0e\xcf\xa0\xfd\xfc\xc2\xc8\x34\x02\x7b\x03\x4e\xd6\x22\xa4\x28\x84\x74\x9a\xcd\xe8\x7f\x19\x32\x54\x31\xab\x53\x24\xa3\xd9\x78\xb0\xb9\x5f\xe6\xe9\x3c\x1b\xec\x64\xba\x38\xc7\xf3\x3c\x83\x52\x93\xb5\x0a\x9b\x07\x5f\xc8\xca\x48\x37\x37\x8a\x49\x37\xa8\x6c\x60\x5e\xdf\xe4\x57\x0a\x69\x0d\x7e\x06\xec\x7c\x2f\x6b\xf1\xe9\x92\xe3\x25\xa2\x8a\xe6\x7f\xe6\x7a\x18\xc6\x2d\x5c\x03\x73\xf3\x0d\xe1\x16\x5c\x21\x92\x57\x81\x76\xbf\xe3\xa9\x57\x69\x0e\xd9\x2c\x22\xc6\xf0\x7d\x32\x0c\x41\x6b\x5f\x52\xaf\xca\x54\xbb\xd8\xdf\x9c\x20\x8d\xd7\x47\xde\x67\x80\x89\xb9\xd9\x11\xc0\xc9\x86\xd4\x33\xd3\x81\x68\x08\xa7\x83\x21\x3c\xb1\x5f\xf4\x69\xab\x1c\x5c\x4f\xec\xef\x02\xc3\x77\xf5\xb2\x1a\x08\xf0\xf8\x75\x6b\x12\x0f\x6a\xa4\x81\x56\x4d\xc3\x7d\x55\xfc\x0f\x79\x45\xa6\x4c\x33\x58\x91\x97\x26\x6c\x4d\x77\x4b\x5d\x0b\xcd\xac\x29\x66\xdb\x84\x1f\x6a\xad\x3c\x02\xbb\x4d\xe0\x40\xdd\x8a\xdc\xdf\xae\xc8\x9f\x96\x24\x84\x82\x23\x0c\x7f\xdd\x93\x06\x0e\x53\xb4\x18\x6c\x29\x9c\x3f\x14\x63\xf4\x60\x26\x9e\x77\x1f\x8d\x5e\xae\x4d\x7c\x1b\x5a\xf3\x72\x67\x89\x19\x9a\x09\xa3\x58\x08\x64\xe5\xd7\xe7\xd2\xcd\xa4\x90\x80\x45\x64\xe1\x7e\xfd\x2b\x29\xaf\xaa\x11\xfb\xe2\x5c\xfc\x0c\x00\x00\xff\xff\xb3\x48\x6d\x8e\x6e\x07\x00\x00") func schemasManifestJsonBytes() ([]byte, error) { return bindataRead( @@ -84,8 +84,8 @@ func schemasManifestJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "schemas/manifest.json", size: 1841, mode: os.FileMode(0644), modTime: time.Unix(1580210584, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x15, 0xc6, 0x93, 0xc2, 0xc1, 0x9b, 0xe4, 0xde, 0xe2, 0x9d, 0xac, 0xaf, 0x15, 0x52, 0x34, 0xc1, 0x2b, 0x3d, 0xf1, 0x55, 0x31, 0x1d, 0x49, 0xcc, 0x34, 0x69, 0xcd, 0xd8, 0x21, 0x24, 0x73, 0xb7}} + info := bindataFileInfo{name: "schemas/manifest.json", size: 1902, mode: os.FileMode(0644), modTime: time.Unix(1586454269, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x80, 0x91, 0x57, 0x15, 0x23, 0x1b, 0x55, 0x70, 0x27, 0x3, 0xfc, 0xf7, 0xa2, 0xc4, 0x2d, 0x9, 0x58, 0x71, 0xea, 0x44, 0x6b, 0xef, 0x15, 0xa, 0xf3, 0x2b, 0x9e, 0x5c, 0x2d, 0x9e, 0x51, 0x6c}} return a, nil } diff --git a/schemas/manifest.json b/schemas/manifest.json index e1fd064..ab89c64 100644 --- a/schemas/manifest.json +++ b/schemas/manifest.json @@ -44,6 +44,7 @@ "type": "object", "properties": { "name": { "type": "string", "minLength": 1 }, + "description": { "type": "string", "minLength": 1 }, "version": { "type": "string", "minLength": 1 }, "log": { "type": "object", diff --git a/test/data/manifest_test_valid.yaml b/test/data/manifest_test_valid.yaml index 1cc771a..1db8fd0 100644 --- a/test/data/manifest_test_valid.yaml +++ b/test/data/manifest_test_valid.yaml @@ -31,6 +31,7 @@ options: config: name: centry + description: A description from manifest file version: 1.0.0 log: level: debug diff --git a/test/data/runtime_test.yaml b/test/data/runtime_test.yaml index d09f771..abc9c96 100644 --- a/test/data/runtime_test.yaml +++ b/test/data/runtime_test.yaml @@ -43,6 +43,7 @@ options: config: name: centry + description: A manifest file used for testing purposes version: 1.0.0 log: level: debug diff --git a/test/data/runtime_test_default_config.yaml b/test/data/runtime_test_default_config.yaml new file mode 100644 index 0000000..d30c194 --- /dev/null +++ b/test/data/runtime_test_default_config.yaml @@ -0,0 +1,4 @@ +commands: [] +config: + name: name + version: version