Skip to content

Commit

Permalink
- Enabled overriding the printed version using an environment variable.
Browse files Browse the repository at this point in the history
- Removed version from required property in the config object.
  • Loading branch information
Kristoffer Ahl committed Oct 15, 2020
1 parent 98ee134 commit 82a1253
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
18 changes: 18 additions & 0 deletions cmd/centry/environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"
"os"
"strings"
)

func overrideFromEnvironment(runtime *Runtime) {
context := runtime.context
cli := runtime.cli
envVersionName := fmt.Sprintf("%s_VERSION", strings.ToUpper(context.manifest.Config.Name))
envVersion := os.Getenv(envVersionName)
if envVersion != "" {
runtime.events = append(runtime.events, fmt.Sprintf("Setting the version from environment variable \"%s\"", envVersionName))
cli.Version = envVersion
}
}
3 changes: 3 additions & 0 deletions cmd/centry/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func NewRuntime(inputArgs []string, context *Context) (*Runtime, error) {
},
}

// Environment overrides
overrideFromEnvironment(runtime)

// Register internal commands
registerInternalCommands(runtime)

Expand Down
2 changes: 1 addition & 1 deletion examples/centry/centry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ options:
config:
name: centry
description: A tool for building declarative CLI's over bash scripts, written in go
version: 1.0.0
version: 1.0.0 # NOTE: This can also be set from an environment variable
log:
level: info
prefix: '[centry] '
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/config/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemas/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"hideInternalCommands": { "type": "boolean" },
"hideInternalOptions": { "type": "boolean" }
},
"required": [ "name", "version" ]
"required": [ "name" ]
}
},
"required": [ "commands", "config" ]
Expand Down
1 change: 0 additions & 1 deletion test/data/runtime_test_default_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
commands: []
config:
name: name
version: version

0 comments on commit 82a1253

Please sign in to comment.