Skip to content

Commit

Permalink
Added runOnce flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriiklymiuk committed Apr 2, 2024
1 parent 5ca286b commit e9bbbd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
}
10 changes: 10 additions & 0 deletions utils/cobraFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -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) {
Expand Down

0 comments on commit e9bbbd6

Please sign in to comment.