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.

Handling top level command

See original GitHub issue

Maybe I’m missing something, but how do I handle the top level command?

args
  .command('a', 'Import data', a)
  .command('b', 'Export data', b)

This will run a or b if I run ./cmd a or ./cmd b.

But if I run ./cmd, it’s hanging (cause my script opens db connection), how do I a) print help or b) execute some code?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
KidkAroliscommented, Jun 29, 2019

No. I will post a reproducible example shortly.

On Sat, 29 Jun 2019 at 12:21, Marvin Mieth notifications@github.com wrote:

Hey @KidkArolis https://github.com/KidkArolis you can show the Help on your main command (with no arguments) with this function: .showHelp(). It is listed in the Docs: [image: Bildschirmfoto 2019-06-29 um 12 20 01] https://user-images.githubusercontent.com/8714775/60382775-40720000-9a68-11e9-8403-f3c5e09a3350.png

Does this fix your problem?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/leo/args/issues/141?email_source=notifications&email_token=AACPGWAD4LT6RR7WQA3M7YTP44ZRLA5CNFSM4HZJ4NO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY3WG6Y#issuecomment-506946427, or mute the thread https://github.com/notifications/unsubscribe-auth/AACPGWG2DUNWZRVPRVLTP53P44ZRLANCNFSM4HZJ4NOQ .

0reactions
KidkAroliscommented, Jun 30, 2019

Here’s what I mean, taking the example from README (slightly modified):

#!/usr/bin/env node

const args = require('args')

args
  .option('port', 'The port on which the app will be running', 3000)
  .option('reload', 'Enable/disable livereloading')
  .command('serve', 'Serve your static site', serve, ['s'])

const flags = args.parse(process.argv)

function serve () {
  console.log('serving...')
}

This works fine:

$ ./hello serve
serving...
$ 

But how do I make sure that the following executions print help:

$ ./hello badcommand
$
$ ./hello
$

I’m thinking… perhaps loop over args.details.commands to match sub against each command…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top Level Commands
MM> Top Level Commands​​ BASIC Top-Level commands. CONTINUE - return to an unfinished SEND, after aborting or QUITting. CUSTOMIZATION commands. FILING commands.
Read more >
The Top Level - Franz Inc.
A break level is exited by using one of the :pop, :prt, :continue, :restart, :return, or :reset commands, or by execution of any...
Read more >
CLI Top-Level Commands - Avi Networks
CLI Top-Level Commands ; clear, Clear the statistics or value of a designated object. ; configure, Create or modify a new or existing...
Read more >
What do you mean by low-level commands and high-level ...
A high-level command abstracts away a lot of the details, putting the knowledge in the tool. This normally makes them much easier to...
Read more >
Top level command action does not work. #978 - GitHub
I do not think there is support for invoking the "top-level" command action handler this way when there is a sub-command as well....
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