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.

Use command line arguments for scripts.

See original GitHub issue

What?

I think it would be easier to specify npm run scripts with command line arguments rather, as it would allow greater diversity in scripts that are runnable.

Example:

As an example I will use a simple add method that take command line arguments in its script:

// add.js
// adds two integers received as command line arguments
function add(a, b) {
    return parseInt(a)+parseInt(b);
}
if(!process.argv[2] || !process.argv[3]) {
    console.log('Insufficient number of arguments! Give two numbers please!');
}
else {
    console.log('The sum of', process.argv[2], 'and', process.argv[3], 'is', add(process.argv[2], process.argv[3]));
}

The script becomes:

"js-add": "node add.js"

To run the script:

npm run js-add 2 3

Giving an output of:

The sum of 2 and 3 is 5

Relevance to vue-cli-plugin-cordova?

Using this method:

npm run cordova-serve-ios

can be replace with:

npm run cordova serve ios

This would be ideal in my situation, as I can’t build my ios projects on the command line. So my typical build command would be cordova prepare ios and then I would run the app through xcode. But because your cli commands don’t allow for cordova prepare ios I can’t do this.

This way would also make adding commands like cordova prepare ios easier.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
JohnRSimcommented, Dec 20, 2018

Any progress with adding build.json support 😃

5reactions
m0dch3ncommented, Dec 4, 2018

ok, I’ll give build.json a try, and we can mention and explain this in the README for the “advanced” users

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Command Line Arguments in a Bash Script
Learn how to use command-line arguments inside the bash script.
Read more >
Bash Script - How to use Command Line Arguments
In this article, let us see about Command Line Arguments usage in Bash script. Arguments are inputs that are necessary to process the...
Read more >
How to Read Command Line Arguments in Shell Scripts?
Command -line arguments are parameters that are passed to a script while executing them in the bash shell. They are also known as...
Read more >
Adding arguments and options to your Bash scripts - Red Hat
Bash uses a tool called positional parameters to provide a means of entering data into a Bash program when it is invoked from...
Read more >
Command Line Arguments - Linux Hint
You can handle command-line arguments in a bash script in two ways. One is by using argument variables, and another is by using...
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