Skip to content
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

Merged
merged 17 commits into from
Mar 20, 2021
Merged

Add rules #171

merged 17 commits into from
Mar 20, 2021

Conversation

cyx
Copy link
Contributor

@cyx cyx commented Mar 19, 2021

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

asciicast

@cyx cyx marked this pull request as ready for review March 19, 2021 23:11
@Widcket Widcket requested a review from a team March 19, 2021 23:19
@cyx cyx force-pushed the add-rules branch 2 times, most recently from fa79f50 to 9f9a487 Compare March 20, 2021 16:37
Comment on lines 137 to 143
if !f.IsRequired {
return false
}

Copy link
Contributor Author

@cyx cyx Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Widcket @jfatta btw this was a subtle bug -- TL;DR if it's AskU / RegisterU and not required, we should not prompt for it. The assumption is most of our endpoints do PATCH semantics so for instance updating a rule shouldn't require the user to also update the name.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2021-03-20 at 11 00 19 AM

So when I undo this change even rebased on main I still get prompted for the Name. I think despite us passing isRequired in TextInput -- we'll still end up prompting for the Name -- which isn't the intent, correct?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor

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.

Comment on lines 18 to 41
// 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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfatta @Widcket While iterating on this rules feature, the difference between create requiring a name and update not -- made me first repeat the same struct.

This is an approach to DRY up that. Lemme know what you think :)

Comment on lines 108 to 110
if err := ruleName.Required().Ask(cmd, &inputs.Name); err != nil {
return err
}
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@cyx cyx Mar 20, 2021

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?

Copy link
Contributor

@Widcket Widcket Mar 20, 2021

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).

Copy link
Contributor

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.

Copy link
Contributor Author

@cyx cyx Mar 20, 2021

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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?

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 🙂

},
}

ruleName.Required().RegisterString(cmd, &inputs.Name, "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto ^

Copy link
Contributor

@Widcket Widcket left a 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 💪🏻

@Widcket Widcket merged commit a1ba34b into main Mar 20, 2021
@Widcket Widcket deleted the add-rules branch March 20, 2021 22:47
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