Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

cobra object support #117

wants to merge 1 commit into from

Conversation

iignatevich
Copy link
Collaborator

No description provided.

defaultJSON = string(jsonBytes)
}
}
val = flags.StringP(param.Name, param.Shorthand, defaultJSON, desc+" (JSON format)")
Copy link
Collaborator

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.

@@ -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 := "{}"
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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.

@iignatevich iignatevich force-pushed the cobra_object_support branch 4 times, most recently from 5d9caf6 to 76b5b56 Compare July 4, 2025 13:47
@@ -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
Copy link
Collaborator Author

@iignatevich iignatevich Jul 4, 2025

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

@iignatevich iignatevich force-pushed the cobra_object_support branch from 76b5b56 to 177a6ba Compare July 4, 2025 14:12
@iignatevich iignatevich force-pushed the cobra_object_support branch from 177a6ba to b57ca11 Compare July 4, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants