Skip to content

Commit

Permalink
feat ✨: add flag to exit when the user command fails
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Hang <[email protected]>
  • Loading branch information
Banh-Canh committed Dec 27, 2024
1 parent 79a18ce commit 10bc730
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
var (
versionFlag bool
nowFlag bool
exitFailFlag bool
version string
logLevelFlag string
sourceFlag string
Expand Down Expand Up @@ -106,6 +107,9 @@ Ginx is a cli tool that watch a remote repository and run an arbitrary command o
if len(args) > 0 {
utils.Logger.Info("Running command.", zap.String("command", args[0]), zap.Any("args", args[1:]))
if err := utils.RunCommand(dir, args[0], args[1:]...); err != nil {
if exitFailFlag {
utils.Logger.Fatal("Failed to run command.", zap.Error(err))
}
utils.Logger.Error("Failed to run command.", zap.Error(err))
}
}
Expand Down Expand Up @@ -142,6 +146,7 @@ func Execute() {
func init() {
RootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "display version information")
RootCmd.Flags().BoolVarP(&nowFlag, "now", "", false, "run the command on the targeted branch now")
RootCmd.Flags().BoolVarP(&exitFailFlag, "exit-on-fail", "", false, "exit on command fail")
RootCmd.PersistentFlags().StringVarP(&logLevelFlag, "log-level", "l", "info", "override log level (debug, info, error)")
RootCmd.PersistentFlags().StringVarP(&sourceFlag, "source", "s", "", "git repository to watch")
RootCmd.PersistentFlags().StringVarP(&branchFlag, "branch", "b", "main", "branch to watch")
Expand Down
3 changes: 2 additions & 1 deletion docs/ginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ginx [flags] -- <command>

```
-b, --branch string branch to watch (default "main")
--exit-on-fail exit on command fail
-h, --help help for ginx
-n, --interval int interval in seconds to poll the remote repo (default 30)
-l, --log-level string override log level (debug, info, error) (default "info")
Expand All @@ -24,4 +25,4 @@ ginx [flags] -- <command>
-v, --version display version information
```

###### Auto generated by spf13/cobra on 22-Dec-2024
###### Auto generated by spf13/cobra on 27-Dec-2024

0 comments on commit 10bc730

Please sign in to comment.