-
Notifications
You must be signed in to change notification settings - Fork 229
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
Feature/early eval for parameterized options #316
base: main
Are you sure you want to change the base?
Feature/early eval for parameterized options #316
Conversation
Thanks for the contribution! Will take a look at it soon and play around with it. |
efffba1
to
43c3c8d
Compare
Interesting approach you went with - I like that you didn't break existing behavior to do this. I'm still thinking about this, reviewed part of it so far, will try to finish it today. At a high level, I think lazy-evaluated parameters is a pretty cool concept. I think it belongs in Pet, can't see why not. It does add some complexity and risks bugs but if it's an isolated feature then should be ok. I don't LOVE the fact that we're using the multi-default-value for this - maybe it's better to create a special representation here, but we risk creating too many special formats making pet hard to use - but also it's not too bad given that there's no reason for anyone to use multi-default-value repr for a single value. On the other hand, we are blocking people from ever using multiple lazy-evaluated default values (ex. having 2 commands as separate choices). But that seems super unlikely to me - hard time thinking of a realistic usecase for that. Idk, let this thought simmer maybe we come up with some other idea worth considering. |
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.
lgtm generally. left some small comments.
One more thing: please document this well in the README so people know how to do this.
Optionally, if you're able to, consider also documenting multi-default value usage in the 'pet new' command description. I believe that's still lacking.
dialog/dynamic_options.go
Outdated
// Example: | ||
// | ||
// DynamicOptions("$(fd -tf --hidden --no-ignore --max-depth=1 .)") | ||
func DynamicOptions(what string) ([]string, error) { |
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 function feels a bit strange - the fact that it accepts a string starting and ending with $() feels weird to me usage wise.
It might read a little nicer if we break it down one more step. Here we can relax the strictness of the check inside EvaluateDynamicOptions (works for any string now, if no dynamic options found inside it it'll just error out). We will have to regex match inside the evaluate now though, but
input := "pgcli -h $(get_available_hosts) -p 5432"
if hasDynamicOptions(input) {
dynamicOptions, err := EvaluateDynamicOptions(input)
// do stuff
}
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.
@RamiAwar just updated the PR with your suggestions Pls review it again.
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.
Better, but still is a bit off. I'd like hasDynamicOptions
to also support dynamic options that are in the middle of the string, not just strings that start with "$(" and end with ")".
This makes it easier to use, harder to misuse.
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.
got it. Will work on that.
Just added the support to use in the middle of the string (allowing to have a prefix/suffix)
However, as described in the godoc, I'm still evaluating just the outermost command,
so if the user plan to have several commands nested like $(command $(with $(nested $(output) ) )
, it'll took the whole string and send it to /bin/sh
, so the shell
will be responsible to evaluate with
and nested
, and therefore, if you don't have support to it, like cmd
, than you cannot do nested evaluations.
Is it ok with this approach?
43c3c8d
to
b92c25e
Compare
Allow to pass commands in the middle of the string and therefore, allow you to have a "prefix/suffix" for each option.
7d3c484
to
8661af2
Compare
Description of changes:
Add support to early eval an option item.
In this case (last scenario), it'll execute
ls
usingcmd/runner/Run
function (which keeps record of folder and shell to use), before create the gui, therefore, allowing user to just select one of the output elements.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.