Is there a way to create subcommands? #651
-
Hopefully this has not already been addressed, if so my apologies. Very simple I have a category of tasks and as opposed to prepending each with the category such as "asdf_start", "asdf_stop", etc. I'm curious if there is a way to call them like "cargo make asdf start", "cargo make asdf stop"? If there is no standardized convention to set this up in the toml, I was thinking something along the lines of a task that takes an input parameter and combines it to then call the respective cargo make task. Not the most elegant but I believe it should work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
ya you can do it via duckscript pretty easily. |
Beta Was this translation helpful? Give feedback.
-
here is an example. its very interesting question so I created an example and updated the README, basically, if you want to be able to do: cargo make server start
cargo make server stop
cargo make client start
cargo make client stop you can define it as follows: [tasks.server]
private = false
extend = "subcommand"
env = { "SUBCOMMAND_PREFIX" = "server" }
[tasks.client]
private = false
extend = "subcommand"
env = { "SUBCOMMAND_PREFIX" = "client" }
[tasks.subcommand]
private = true
script = '''
#!@duckscript
cm_run_task ${SUBCOMMAND_PREFIX}_${1}
'''
[tasks.server_start]
private = true
command = "echo"
args = ["starting server..."]
[tasks.server_stop]
private = true
command = "echo"
args = ["stopping server..."]
[tasks.client_start]
private = true
command = "echo"
args = ["starting client..."]
[tasks.client_stop]
private = true
command = "echo"
args = ["stopping client..."] |
Beta Was this translation helpful? Give feedback.
here is an example. its very interesting question so I created an example and updated the README,
see https://github.com/sagiegurari/cargo-make#usage-command-groups
basically, if you want to be able to do:
you can define it as follows: