fresh-yak-35965
06/10/2024, 5:05 PMmicroscopic-river-74022
06/10/2024, 5:05 PMmicroscopic-river-74022
06/10/2024, 5:05 PMargs
and opts
fields to explicitly define positional arguments and options that are expected or required for your command. These are validated and parsed before running the command.
Here's an example of how you can define a Run action:
yaml
kind: Command
name: wrapped
description:
short: Execute a Run action with arguments and option flags
args:
- name: action-name
description: The name of the Run action
required: true
opts:
- name: db
description: Override the database hostname
type: string
gardenCommand:
- run
- ${args.action-name}
- --var
- dbHostname=${opts.db || "db"}
In this example, a wrapper command is made for executing Run
actions in your project. One positional argument is required for the name of the action to run. An option is also defined for overriding a project variable.
To further accept any additional arguments and append to the Garden command, you can add the following:
yaml
...
gardenCommand:
- run
- ${args.action-name}
- --var
- dbHostname=${opts.db || "db"}
- $concat: ${args.$rest} # <- pass any additional parameters through to the command without validation
Now you could, for example, run garden wrapped my-action --db test --force
and the additional --force
parameter gets passed to the underlying Garden command.
For more details, you can refer to the Garden documentation on defining arguments and option flags ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
06/10/2024, 5:05 PMfresh-yak-35965
06/10/2024, 8:37 PMrevision -m "create table foobar"
which calls the underlying alembic-revision
Run action. How can I accomplish this while also passing the additional option through to the underlying command called by alembic-revision
?microscopic-river-74022
06/10/2024, 8:37 PMmicroscopic-river-74022
06/10/2024, 8:37 PMalembic-revision
Run action and passes through additional options to the underlying command. You can use the args
and opts
fields to define positional arguments and options for your command.
Here's an example of how you can define the custom command:
yaml
kind: Command
name: revision
description:
short: Execute alembic-revision with arguments and option flags
args:
- name: message
description: The message for the alembic revision
required: true
gardenCommand:
- run
- alembic-revision
- --message
- ${{args.message}}
- $concat: ${{args.$rest}} # <- pass any additional parameters through to the command without validation
In this example, a wrapper command named revision
is created for executing the alembic-revision
Run action. One positional argument named message
is required for the revision message. The $concat: ${{args.$rest}}
line allows any additional parameters to be passed through to the alembic-revision
command without validation.
Now you can run your command as garden revision -m "create table foobar"
and the -m "create table foobar"
parameter gets passed to the underlying alembic-revision
command.
Please note that this is a hypothetical example and you may need to adjust it based on the actual requirements of the alembic-revision
Run action.
For more details, you can refer to the Garden documentation on defining arguments and option flags ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
06/10/2024, 8:37 PMmicroscopic-river-74022
06/10/2024, 8:45 PMfresh-yak-35965
06/10/2024, 8:45 PMkind: Command
name: alembic
description:
short: Execute alembic-revision with arguments and option flags
args:
- name: action-name
description: The name of the alembic command
required: true
opts:
- name: message
description: Optional message (for revisions)
type: string
gardenCommand:
- run
- alembic-${args.action-name}
- --var
- message=${args.message || ""}
The error is as follows:
Encountered an unexpected Garden error. This is likely a bug 🍂
You can help by reporting this on GitHub: https://github.com/garden-io/garden/issues/new?labels=bug,crash&template=CRASH.md&title=Crash%3A%20Missing%20cli%20argument%20in%20custom%20command%20wrapper.
Please attach the following information to the bug report after making sure that the error message does not contain sensitive information:
Error: Missing cli argument in custom command wrapper.
at CustomCommandWrapper.action (file:///Users/jackhall/Library/Application%20Support/io.garden.garden/1715180386-vPlqQaa.r/rollup/garden.mjs:425756:23)
at file:///Users/jackhall/Library/Application%20Support/io.garden.garden/1715180386-vPlqQaa.r/rollup/garden.mjs:358999:41
at async file:///Users/jackhall/Library/Application%20Support/io.garden.garden/1715180386-vPlqQaa.r/rollup/garden.mjs:358787:20
microscopic-river-74022
06/10/2024, 8:45 PMgardenCommand
field, you're trying to use args.action-name
and args.message
as variables. However, the error might be due to the fact that these variables are not being correctly interpolated.
In Garden, when you want to use variables in the gardenCommand
field, you should wrap them in ${}
. This tells Garden to replace the ${}
with the value of the variable.
Here's how you can modify your command:
yaml
kind: Command
name: alembic
description:
short: Execute alembic-revision with arguments and option flags
args:
- name: action-name
description: The name of the alembic command
required: true
opts:
- name: message
description: Optional message (for revisions)
type: string
gardenCommand:
- run
- alembic-${{args.action-name}}
- --var
- message=${{opts.message || ""}}
In this corrected version, ${{args.action-name}}
and ${{opts.message || ""}}
are used in the gardenCommand
field, which should correctly interpolate the variables.
For more details, you can refer to the Garden documentation on defining arguments and option flags ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
06/10/2024, 8:45 PM