diff --git a/cmd/args.go b/cmd/args.go index 5aadcf0..9954435 100644 --- a/cmd/args.go +++ b/cmd/args.go @@ -281,18 +281,28 @@ var rootCmd = &cobra.Command{ Use: "gh-commit", Short: "gh-commit: commit files easily to git using the Github API", Long: "gh-commit: a CLI tool for committing changes via the Github API, especially useful for working in ephemeral environments.", - RunE: func(cmd *cobra.Command, args []string) error { - version, _ := cmd.Flags().GetBool("version") + PreRunE: func(cmd *cobra.Command, args []string) error { + message, _ := cmd.Flags().GetString(MessageFlag.Long) + branch, _ := cmd.Flags().GetString(BranchFlag.Long) + versionFlag, _ := cmd.Flags().GetBool("version") - if version { + if versionFlag { fmt.Printf("%s %s %s\n", color.New(color.FgBlue, color.Bold).Sprint("🔖 gh-commit"), color.New(color.FgGreen).Sprint(VERSION), color.New(color.Faint).Sprint("(CLI tool)"), ) - return nil + os.Exit(0) + } + + if message == "" || branch == "" { + return fmt.Errorf("--message and --branch are both required flags") } + return nil + }, + RunE: func(cmd *cobra.Command, args []string) error { + path, err := ValidateLocalGit() if err != nil { return err diff --git a/cmd/execute.go b/cmd/execute.go index 9ce0e4f..305a89e 100644 --- a/cmd/execute.go +++ b/cmd/execute.go @@ -11,7 +11,7 @@ import ( ) // VERSION number: changed in CI -const VERSION = "v0.1.0" +const VERSION = "v0.1.1" var rootPath string var repo repository.Repository @@ -33,9 +33,6 @@ func init() { case "stringSlice": rootCmd.Flags().StringSliceP(flag.Long, flag.Short, []string{}, flag.Description) } - if flag.Required { - _ = rootCmd.MarkFlagRequired(flag.Long) - } } rootCmd.Flags().BoolP("version", "V", false, "Print current version")