Skip to content

Commit c27cfa1

Browse files
committed
📝 Updated main.go to handle flag parsing errors more gracefully 🚀
1 parent 1dac76a commit c27cfa1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,24 @@ func main() {
2929
Long: "AI-git is a git wrapper with AI capabilities for certain commands",
3030
DisableFlagParsing: true,
3131
Run: func(cmd *cobra.Command, args []string) {
32-
fmt.Println(args)
3332
if len(args) == 0 {
3433
cmd.Help()
3534
return
3635
}
3736
var newBranch, message string
3837
cmd.Flags().StringVarP(&message, "message", "m", "", "Auto generate commit message")
3938
cmd.Flags().StringVarP(&newBranch, "newBranch", "b", "", "Auto generate branch name")
40-
if err := cmd.Flags().Parse(args); err == nil {
39+
err := cmd.Flags().Parse(args)
40+
if err == nil || strings.Contains(err.Error(), "flag needs an argument") {
4141
// Handle specific commands
4242
switch args[0] {
4343
case "commit":
44-
fmt.Println(cmd.Flags().Changed("message"))
45-
if message == "" {
44+
if err != nil && strings.Contains(err.Error(), "flag needs an argument") && message == "" {
4645
handleCommit(*config)
4746
return
4847
}
4948
case "checkout":
50-
if newBranch == "" {
49+
if err != nil && strings.Contains(err.Error(), "flag needs an argument") && newBranch == "" {
5150
handleCheckout(*config)
5251
return
5352
}

0 commit comments

Comments
 (0)