CLI args shouldn't be parsed when importing package
See original GitHub issueDescription
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:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Fix released in https://github.com/auth0/auth0-deploy-cli/releases/tag/v4.0.3
To whom it may concern, I’ve worked around this issue by removing arguments from
process.argvbefore requiringauth0-deploy-cli.