-
Notifications
You must be signed in to change notification settings - Fork 4
cobra object support #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
cobra object support #117
Conversation
plugins/actionscobra/cobra.go
Outdated
defaultJSON = string(jsonBytes) | ||
} | ||
} | ||
val = flags.StringP(param.Name, param.Shorthand, defaultJSON, desc+" (JSON format)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need tests on how it renders in the templates. Not sure what we have for the moment.
plugins/actionscobra/cobra.go
Outdated
@@ -163,6 +164,16 @@ func setFlag(flags *pflag.FlagSet, param *action.DefParameter) (any, error) { | |||
// @todo use flags.Var() and define a custom value, jsonschema accepts "any". | |||
return nil, fmt.Errorf("json schema array type %q is not implemented", param.Items.Type) | |||
} | |||
case jsonschema.Object: | |||
// Handle object as a JSON string | |||
defaultJSON := "{}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have defaults set elsewhere. Please, make it one way. Maybe define a new Cobra Value Handler. Object must work for arguments and options.
plugins/actionscobra/cobra.go
Outdated
@@ -183,7 +194,21 @@ func derefOpts(opts action.InputParams) action.InputParams { | |||
func derefOpt(v any) any { | |||
switch v := v.(type) { | |||
case *string: | |||
return *v | |||
str := *v | |||
// Check for raw JSON prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it. Please, reflect in the documentation how to use objects.
5d9caf6
to
76b5b56
Compare
docs/actions.schema.md
Outdated
@@ -60,6 +60,7 @@ See [examples](#examples) of how required and default are used and more complex | |||
3. `integer` | |||
4. `number` - float64 values | |||
5. `array` (currently array of 1 supported type) | |||
6. `object` - parses string as json string into map[string]any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update doc
test args and enums
76b5b56
to
177a6ba
Compare
177a6ba
to
b57ca11
Compare
No description provided.