cacjs / cac

Simple yet powerful framework for building command-line apps.
MIT License
2.65k stars 104 forks source link

could I use default command(not the global one with name '@@global@@')? #110

Closed richardo2016 closed 3 years ago

richardo2016 commented 3 years ago

Issue Type

run code below:

cli.command('[...rest]', 'desc')
    .option('--out', 'desc')
    .action(...)

const parsed = cli.parse(['', '', './src', '--out', './lib'], { run: false});

console.log(parsed)

Expected

{
  "args": [
    "./src",
    "abc"
  ],
  "options": {
    "--": [],
    "out": "./lib"
  }
}

Actual

{
  "args": [
    "./src"
  ],
  "options": {
    "--": [],
    "out": true
  }
}

Possible Solutions

Info

richardo2016 commented 3 years ago

finally I found I should customize option like this:

cli.command('[...rest]', 'desc')
    .option('--out [out]', 'desc') // add one option var name with bracket here 🤔
    .action(...)

const parsed = cli.parse(['', '', './src', '--out', './lib'], { run: false});

console.log(parsed)

then cli.parse works as I expected.