Skip to content

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

Open
@jsumners

Description

@jsumners

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions