Repository navigation
Command wrappers: expose the call's arguments as args in args/env templates #15624
Closed
andersonkrs
started this conversation in
Ideas
Replies: 2 comments
|
This sounds good, and the Two choices from your questions:
AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: 2.1.321. |
0 replies
|
Implemented in #15655: feat(shim): expose the call's arguments as argv in wrapper templates |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
[wrappers]templates can readenv,vars,config_rootand so on, but not thearguments the wrapped command was called with. So a wrapper can't change depending on
the subcommand.
My case: I run Rails through fnox, and the secrets profile should depend on what I'm
running.
rails testneeds thetestprofile, and everything else needsdevelopment.Today that means typing
fnox --profile=test exec -- rails test …by hand, or keeping aseparate script or task for each profile. A wrapper should be able to do this.
Proposal
Make the call's arguments available as
args(a list) when rendering a wrapper'sargsand
env.argsonly holds what the user typed after the command name. It doesn'tinclude the wrapper's
commandor its ownargs. The arguments are still forwarded tothe command unchanged, after the wrapper's own
args.rails test models/user_test.rbfnox --profile=test exec -- rails test models/user_test.rbrails serverfnox --profile=development exec -- rails serverrailsfnox --profile=development exec -- railsThe
railsthat fnox launches is the real one, because a wrapper isn't re-applied whileits own command is running. For a Bundler app, end the wrapper's
argswith"bundle", "exec", "rails".Tera 2's conditional expressions, indexing, slices and
inkeep these templates to oneline.
args[0]on an empty list just compares unequal, with no error.More examples
Rails without fnox:
RAILS_ENVby subcommandTurn up logging when a flag appears anywhere
Cargo: a separate target dir for
cargo test, so tests and dev builds don't invalidate each otherNotes / open questions
argsalways go before the user's arguments. That fits launcherslike
fnox exec --andbundle exec, and choosingenvvalues. It doesn't fit addingflags after a subcommand (
terraform plan -var-file=…). Is a way to place the user'sarguments worth adding later, e.g. a
{{ args }}placeholder that controls where they go?argscould be confused with the wrapper's ownargskey. Wouldargvorcall_argsbe clearer?I have a working implementation with docs and an e2e test, and I'm happy to share it if
this direction sounds good.
I also dropped "optional chaining" from the Tera sentence, since no example uses it now. In the earlier test, the test and development results were the same as they are here.
Maybe there's a better way to separate my
testanddevelopmentfnox secrets without using profiles, but I think it fits very well withfnox exec. For example I have specific RAILS_MASTER_KEY for each profile that I don't leave on the machine in plain textAll reactions