question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to use 'generic' value as the default command?

See original GitHub issue

Let me try to explain.

I have this CLI:

my-cli something-else
my-cli -h

I want to be able to use what I want as the first argument. Something like this:

// Instead of:
.command('build <entry>')
// just:
.command('<entry>')

is that clear?

A more real example:

prog
    .command('<entry>')
    .describe('List your entries')
    .option('a, --add')
    .action((entry, opts) => {
      console.log('You said:')
      console.log(entry)
     })

I need to be able to run my-cli hello and not only using my-cli a hello

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
galvezcommented, Jun 20, 2018

My solution to this problem:

const makeDefault = (argv, defaultCommand) => {
  argv = [ ...argv ]
  argv.splice(2, 0, 'defaultCommand')
  return argv
}

prog.parse(injectArgv(process.argv, 'myDefaultCommand'))
1reaction
galvezcommented, Jun 20, 2018

Heh, ended up migrating to https://github.com/tj/commander.js/

It has variadic arguments. Didn’t mess up with my CLI help text. Nice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Anyway to default a generic parameter to a certain type?
I don't believe there is a way to default it to a certain type, but you could put that ...
Read more >
When to set defaults for VHDL generics
It's good practice to always mention a default value to generic during entity declaration because it makes sure that the entity can be ......
Read more >
Unable to specify a default value for a generic parameter #3737
I think the problem here is that in general, e.g. if there are other parameters also using _T in their type, the default...
Read more >
value expressions - produce the default value for any type
Use the default value expressions to obtain the default, uninitialized value of a type. The default value expression can be used with generic...
Read more >
GenericValue Variables - UiPath Documentation Portal
Note: When using this method with a GenericValue variable of data type Int, Float or Boolean, the data is automatically converted to String...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found