diff --git a/cmd/root.go b/cmd/root.go index 0eb8c1c..d89e44d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -var APP_VERSION = "1.3.3" +var APP_VERSION = "1.3.4" // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ @@ -76,5 +76,11 @@ func init() { "", "Create corgi service from template url", ) + rootCmd.PersistentFlags().BoolP( + "runOnce", + "", + false, + "Run corgi once and exit", + ) rootCmd.SetVersionTemplate("corgi version {{.Version}}\nChangelog: https://github.com/Andriiklymiuk/corgi/releases/tag/v{{.Version}}\n") } diff --git a/utils/cobraFlags.go b/utils/cobraFlags.go index 6f8e84b..22c7081 100644 --- a/utils/cobraFlags.go +++ b/utils/cobraFlags.go @@ -2,6 +2,7 @@ package utils import ( "fmt" + "os" "github.com/spf13/cobra" ) @@ -16,6 +17,15 @@ func CheckForFlagAndExecuteMake(cmd *cobra.Command, flag string, cmdName string) return } ExecuteForEachService(cmdName) + + isRunOnce, err := cmd.Root().Flags().GetBool("runOnce") + if err != nil { + return + } + if isRunOnce { + PrintFinalMessage() + os.Exit(0) + } } func ExecuteForEachService(cmdName string) {