Skip to content

How to include a boolean option in front of an argument #576

Answered by c4spar
SamEdwardes asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @SamEdwardes,

yes you can achieve the same with cliffy.

If you want that your option takes no value, then simple remove the argument from the option:

new Command()
  .option("-y, --yes", "Would you like to?")

If you want your option to take an optional value, you can add an equal sign between the flag and the value. This requires adding an equal sign when passing a value to the flag.

new Command()
  .option("-y, --yes=[yes:boolean]", "Would you like to?")

Than you can call it like this:

$ deno run reprex.ts -y "sam"
--yes: true
argument: sam
$ deno run reprex.ts -y=true "sam"
--yes: true
argument: sam
$ deno run reprex.ts -y=0 "sam"
--yes: false
argument: sam

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SamEdwardes
Comment options

Answer selected by SamEdwardes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #575 on March 29, 2023 21:52.