How to pass options before a sub-command ?
See original GitHub issueHello,
Thanks a lot for the cliffy work, I just started using it but I already love the method chaining approach;
However I’d like to build a CLI in a way that doesn’t seem to be allowed by the framework
abcdctl -a localhost -p 8080 chain --from source --to destination --amount 69
My basic command abcd has several sub-commands (in this example chain
), but the server arguments (-a
for the addr & -p
for the port) are global to all sub-commands
Here is my try
let remote: Client;
await new Command()
.name("abctl")
.version("1.0.0")
.description("Interact with abcd")
.option("-a, --address <addr>", "HTTP endpoint", { default: "localhost" })
.option("-p, --port <port>", "HTTP port", { default: 8080 })
.action(async ({ address, port }: { address: string; port: number }) => {
remote = await new Client(address, port).co.catch(_ => Deno.exit(1));
await remote?.ping().then(console.dir);
})
.command("chain", new Command()
.description("Interact with blockchain")
.version("0.1.0")
.option("-f, --from <from:string>", "Source wallet")
.option("-t, --to <to:string>", "Destination wallet")
.option("-a, --amount <amount:number>", "Amount")
.action(async ({ from, to, amount } : {
from: string,
to: string,
amount: number
}) => {
const response = await remote.chainadd(from, to, amount);
console.dir(response);
Deno.exit(0)
})
)
.parse(Deno.args);
The problem is that when I execute the example I get an error stating that the “chain” command does not exist (and it offers me to try “chain” instead)
Is my objective reachable with this framework or I must change my approach ?
Thanks a lot
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to add common options to sub commands which can go ...
Click strictly separates parameters between commands and subcommands. What this means is that options and arguments for a specific command ...
Read more >How do I configure global options for all subcommands? #895
The obvious use case here is logging. This issue isn't about how to specify global options (e.g. an option that works for all...
Read more >Clikt - Common Options With Subcommands
You can define your options on the root command and pass down the information via the context. With this design, you'll have to...
Read more >Adding arguments and options to your Bash scripts - Red Hat
The ability to use positional parameters—otherwise known as arguments—to specify data to be used as values for variables in the scripts is one ......
Read more >Picocli subcommands - aragost.com
The subcommand is specifed as a parameter to the main application. Arguments passed before the subcommand name are considered to belong to the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @c4spar the arguments before the sub command are common and required by all sub commands, that’s why I’d rather see them before the sub command even if it is not a hard requirement
It’s now supported in v0.24.3 😉