|
6 | 6 | "fmt"
|
7 | 7 | "os"
|
8 | 8 | "path/filepath"
|
| 9 | + "strconv" |
9 | 10 | "strings"
|
10 | 11 | "time"
|
11 | 12 |
|
@@ -91,16 +92,28 @@ func processCustomCommands(
|
91 | 92 | // Process and add flags to the command
|
92 | 93 | for _, flag := range commandConfig.Flags {
|
93 | 94 | if flag.Type == "bool" {
|
| 95 | + defaultVal := false |
| 96 | + if flag.Default != "" { |
| 97 | + // Accept "true"/"false" as string for bool default |
| 98 | + parsed, err := strconv.ParseBool(flag.Default) |
| 99 | + if err == nil { |
| 100 | + defaultVal = parsed |
| 101 | + } |
| 102 | + } |
94 | 103 | if flag.Shorthand != "" {
|
95 |
| - customCommand.PersistentFlags().BoolP(flag.Name, flag.Shorthand, false, flag.Usage) |
| 104 | + customCommand.PersistentFlags().BoolP(flag.Name, flag.Shorthand, defaultVal, flag.Usage) |
96 | 105 | } else {
|
97 |
| - customCommand.PersistentFlags().Bool(flag.Name, false, flag.Usage) |
| 106 | + customCommand.PersistentFlags().Bool(flag.Name, defaultVal, flag.Usage) |
98 | 107 | }
|
99 | 108 | } else {
|
| 109 | + defaultVal := "" |
| 110 | + if flag.Default != "" { |
| 111 | + defaultVal = flag.Default |
| 112 | + } |
100 | 113 | if flag.Shorthand != "" {
|
101 |
| - customCommand.PersistentFlags().StringP(flag.Name, flag.Shorthand, "", flag.Usage) |
| 114 | + customCommand.PersistentFlags().StringP(flag.Name, flag.Shorthand, defaultVal, flag.Usage) |
102 | 115 | } else {
|
103 |
| - customCommand.PersistentFlags().String(flag.Name, "", flag.Usage) |
| 116 | + customCommand.PersistentFlags().String(flag.Name, defaultVal, flag.Usage) |
104 | 117 | }
|
105 | 118 | }
|
106 | 119 |
|
|
0 commit comments