From cf958978010ab861d30ce79d18056d82038fa0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=A0=CF=85=CE=B1=CE=B7=20=D7=A0=CF=85=CE=B1=CE=B7=D1=95?= =?UTF-8?q?=CF=83=CE=B7?= Date: Sun, 3 Dec 2023 11:13:10 -0800 Subject: [PATCH] fix: version should not require gilt file --- cmd/overlay.go | 5 +++-- cmd/root.go | 8 +++----- test/integration/test_cli.bats | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/overlay.go b/cmd/overlay.go index 7414ea4..f8eec51 100644 --- a/cmd/overlay.go +++ b/cmd/overlay.go @@ -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 diff --git a/cmd/root.go b/cmd/root.go index e37f26e..be7eae4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,8 +36,8 @@ import ( ) var ( - repos pkg.RepositoriesManager logger *slog.Logger + repos pkg.RepositoriesManager appConfig config.Repositories ) @@ -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") @@ -99,7 +96,8 @@ func initLogger() { ) } -func initConfig() { +func initConfig(cmd *cobra.Command, args []string) { + initLogger() viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.SetConfigType("yaml") diff --git a/test/integration/test_cli.bats b/test/integration/test_cli.bats index d30625d..405bae0 100644 --- a/test/integration/test_cli.bats +++ b/test/integration/test_cli.bats @@ -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'