-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add rules #171
Conversation
fa79f50
to
9f9a487
Compare
internal/cli/flags.go
Outdated
if !f.IsRequired { | ||
return false | ||
} | ||
|
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.
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 think this change fixes it.
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.
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.
That's correct, if it is not a required input it should not prompt for it on update.
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.
Good catch!
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.
With this change apps update
no longer prompts for callback URL. We should add a property for always prompting for that use case then.
internal/cli/flags.go
Outdated
// Required clones an existing flag and assigns `IsRequired` to true. This is | ||
// useful when there are flags with several different use cases -- e.g. create | ||
// requiring the flag, but update not requiring it. | ||
func (f *Flag) Required() *Flag { | ||
clone := *f | ||
clone.IsRequired = true | ||
return &clone | ||
} | ||
|
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.
internal/cli/rules.go
Outdated
if err := ruleName.Required().Ask(cmd, &inputs.Name); err != nil { | ||
return err | ||
} |
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.
This is the bit which utilizes this new proposed feature of adding Required()
fluent semantics to only have to define a flag once and re-define it based on usecase.
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.
Should't using AskU
on the update command handle that?
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.
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.
Gotcha, yeah I think maybe I might have had a different expectation. So to step back, wanna clarify:
Given
Name: required
Create
Should always prompt for Name, and will fail if none is supplied.
Update
Should not prompt for Name, and will not fail if none is supplied.
Is my understanding of intent correct?
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.
Yup.
On create, if not passed the command should prompt for it.
On update should only prompt if no local flag (any at all) is passed.
If Name wasn't a required input, it should not be prompted on update (regardless of local flags), unless manually specified otherwise (e.g. an important but not required field).
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 should document this somewhere.
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.
Gotcha, based on the callback URL discussion wonder if we need a different property (e.g. AlwaysPrompt bool
) or something similar for the case of callback URL in matias' post.
In this case, if we had AlwaysAsk: false
in the Name
field for rules, we can then skip asking for it on update (even if there were no local flags passed). What do you think?
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.
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.
Gotcha, based on the callback URL discussion wonder if we need a different property (e.g.
AlwaysPrompt bool
) or something similar for the case of callback URL in matias' post.In this case, if we had
AlwaysAsk: false
in theName
field for rules, we can then skip asking for it on update (even if there were no local flags passed). What do you think?
Yes, adding a property for that would solve this use case. In the first PoC for the refactor I added it and then removed because it wasn't needed yet. Now it is 🙂
internal/cli/rules.go
Outdated
}, | ||
} | ||
|
||
ruleName.Required().RegisterString(cmd, &inputs.Name, "") |
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.
Ditto ^
Pick 5 templates to start.
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.
Add a boolean property to Flag
to signal that it should always be prompted, and modify the prompt logic to take it into account, and the PR should be ready to go 💪🏻
Description
This adds LIST, SHOW, CREATE, UPDATE, and DELETE operations for rules. At the moment we've left out the
Order
field altogether -- we can either consider having that in the future or completely leave re-ordering in the UI since that's a lot more intuitive.Demo