Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow the .command() method to accept a function that returns an object #2227

Copy link
Copy link

Description

@ajimae
Issue body actions

First I would like to thank everyone directly or indirectly involved in making this library possible and who work tirelessly to maintain this awesome library, more grease to your elbow.

I was wondering if we can have another overloaded method that will allow function yargs.command(cb) to accept a callback (which accepts an argv object) and returns a command object?

function commandOption(argv) {
  return {
    command: 'argv.command',
    describe: 'description',
    builder: {
      containerKey: {
        type: 'string',
        describe: 'script [argv.command]',
        demandOption: true,
        alias: 'a'
      }
    },
    handler: function () {
       // handler function body
    }
  }
}

// entry point
yargs
  .middleware(middleware)
  .command(commandOption)
  .fail(catchError)
  .help(true)
  .argv;

Right now the option needs to be explicitly passed as an object into the .command() method.

I ran into a specific issue that could have saved me a lot of stress if only the .commnad() method could accept a function.

I don't know if this is achievable.

Thanks

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.