Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot lazy parse and support help/version at same time #56

Open
jsumners opened this issue Oct 26, 2022 · 1 comment
Open

Cannot lazy parse and support help/version at same time #56

jsumners opened this issue Oct 26, 2022 · 1 comment

Comments

@jsumners
Copy link

sade/src/index.js

Lines 150 to 152 in 1cdf3e4

// show main help if relied on "default" for multi-cmd
if (argv.help) return this.help(!isSingle && !isVoid && name);
if (argv.version) return this._version();

The early return here will break the following:

const prog = sade('cool-cli', true).version('1.0.0').describe('Some cool CLI.')

const {args} = prog.parse(process.argv, {lazy: true})

if (args.something) {
  // do stuff
}

This is inconsistent with the documentation:

sade/readme.md

Lines 638 to 653 in 1cdf3e4

#### opts.lazy
Type: `Boolean`<br>
Default: `false`
If true, Sade will not immediately execute the `action` handler. Instead, `parse()` will return an object of `{ name, args, handler }` shape, wherein the `name` is the command name, `args` is all arguments that _would be_ passed to the action handler, and `handler` is the function itself.
From this, you may choose when to run the `handler` function. You also have the option to further modify the `args` for any reason, if needed.
```js
let { name, args, handler } = prog.parse(process.argv, { lazy:true });
console.log('> Received command: ', name);
// later on...
handler.apply(null, args);
```

One solution may be to return:

{
  args: [],
  name: '',
  handler: undefined,
  helpOrVersion: true // indicates the user passed one of the options
}
@illarionvk
Copy link

I was able to replicate the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants