[fix] Accept unset `Default` fields (== nil) and use hardwired type-dependent standard defaults for that case.
@@ -48,13 +48,25 @@ func (opts InstallationOptions) AsCobraFlagsFor(cmd *cobra.Command) {
// Declare option's flag, type-dependent
switch opt.Type {
case BooleanType:
+ if opt.Default == nil {
+ cmd.Flags().Bool(flagName, false, opt.Description)
+ } else {
cmd.Flags().Bool(flagName, opt.Default.(bool), opt.Description)
+ }
case StringType:
+ if opt.Default == nil {
+ cmd.Flags().String(flagName, "", opt.Description)
+ } else {
cmd.Flags().String(flagName, opt.Default.(string), opt.Description)
+ }
case IntType:
+ if opt.Default == nil {
+ cmd.Flags().Int(flagName, 0, opt.Description)
+ } else {
cmd.Flags().Int(flagName, opt.Default.(int), opt.Description)
}
}
+ }
return
}
