Skip to content

Commit

Permalink
fix: version should not require gilt file (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
retr0h committed Dec 3, 2023
1 parent fb41821 commit 1ad6731
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cmd/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (

// overlayCmd represents the overlay command
var overlayCmd = &cobra.Command{
Use: "overlay",
Short: "Install gilt dependencies",
Use: "overlay",
Short: "Install gilt dependencies",
PersistentPreRun: initConfig,
RunE: func(cmd *cobra.Command, args []string) error {
// By the time we reach this point, we know that the arguments were
// properly parsed, and we don't want to show the usage if an error
Expand Down
8 changes: 3 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
)

var (
repos pkg.RepositoriesManager
logger *slog.Logger
repos pkg.RepositoriesManager
appConfig config.Repositories
)

Expand Down Expand Up @@ -70,9 +70,6 @@ func Execute() {
}

func init() {
cobra.OnInitialize(initLogger) // initial logger
cobra.OnInitialize(initConfig, initLogger)

rootCmd.PersistentFlags().BoolP("debug", "d", false, "Enable or disable debug mode")
rootCmd.PersistentFlags().
StringP("gilt-dir", "c", "~/.gilt/clone", "Path to Gilt's clone dir")
Expand All @@ -99,7 +96,8 @@ func initLogger() {
)
}

func initConfig() {
func initConfig(cmd *cobra.Command, args []string) {
initLogger()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

viper.SetConfigType("yaml")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ teardown() {
}

@test "invoke gilt version subcommand" {
run go run main.go version
run bash -c "cd ${GILT_TEST_BASE_TMP_DIR}; rm -f Giltfile.yaml; go run ${GILT_PROGRAM} version"

[ "$status" -eq 0 ]
echo "${output}" | jq '.date'
Expand Down

0 comments on commit 1ad6731

Please sign in to comment.