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.

CLI args shouldn't be parsed when importing package

See original GitHub issue

Description

args.argv should only be invoked when require.main === module is true, otherwise a simple require to this module will parse command line arguments unexpectedly. This is specially harmful when you are importing this package at the top of your module and trying to create your own set of command line options.

Reproduction

Create a node.js file importing this package: my_test.js

const Auth0 = require('auth0-deploy-cli');

console.log('CLI arguments: ' + process.argv);

Invoke this file using node: node my_test.js --help

That shouldn’t show auth0-deploy-cli help.

Fix suggestion here: https://github.com/davidrissato/auth0-deploy-cli/commit/ff4104168c47f24d60a10bee9c11e32b8ec4d6ef

Environment

  • Version of this library used: 3.6.1
  • Version of the platform or framework used, if applicable:
  • Other relevant versions (language, server software, OS, browser):
  • Other modules/plugins/libraries that might be involved:

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
shawnmcleancommented, Mar 17, 2020
2reactions
miliboppcommented, Dec 5, 2019

To whom it may concern, I’ve worked around this issue by removing arguments from process.argv before requiring auth0-deploy-cli.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python3 importing module with command line args [duplicate]
If the file is imported, the argparse options are ignored. Also, import train as train is redundant.
Read more >
argparse — Parser for command-line options, arguments and ...
Source code: Lib/argparse.py Tutorial: This page contains the API reference information. For a more gentle introduction to Python command-line parsing, ...
Read more >
Python Command Line Arguments
Python command line arguments are the key to converting your programs into useful and enticing tools that are ready to be used in...
Read more >
Plac: Parsing the Command Line the Easy Way — plac ...
The examples here should have made clear that plac is able to figure out the command-line arguments parser to use from the signature...
Read more >
Package argparse version 0.9.0 - DUB - The D package registry
Parser for command-line arguments. argparse is a self-contained flexible utility to parse command line arguments that can work at compile-time.
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