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.

Wrong parsing of arguments in install-node-and-nmp

See original GitHub issue

I need to provide custom .npmrc to the npm install command. The .npmrc is located in root of my project. My plugin configuration looks as:

<!--Install dependencies using npm-->
<execution>
    <id>npm install</id>
    <goals>
        <goal>npm</goal>
     </goals>
     <configuration>
         <arguments>install --userconfig "${basedir}/.npmrc"</arguments>
     </configuration>
 </execution>

The quotes "" are provided because this runs on my Jenkins CI server and it constructs the temp folder for CI build out of project name which contains spaces. Unfortunately the the args are simply split on \s+ which ignores the quotes hence cannot be used with custom .npmrc located in path which contains spaces. The issue can be seen here:

https://github.com/eirslett/frontend-maven-plugin/blob/master/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeTaskExecutor.java#L79

IMHO the problem is you take all the arguments as single String. I suggest you have option to provide List of arguments instead and take them as they are. To make the change backward compatible you can provide new list property like <argumentsList> and use the one which is set, fail if both are set. The fixed <configuration /> may look like:

<!--Install dependencies using npm-->
<execution>
    <id>npm install</id>
    <goals>
        <goal>npm</goal>
     </goals>
     <configuration>
         <argumentsList>
            <argument>install</argument>
            <argument>--userconfig</argument>
            <argument>"${basedir}/.npmrc"</argument>
         <argumentsList>
     </configuration>
 </execution>

Overall doing split on space looks dangerous to me. Let me know if you need help with this, will be glad to assist.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
janzykacommented, Jan 14, 2016

This is tricky, what you are looking for is really some command line parser. The quotes may be escaped etc. There is whole apache project for that.

As I see it you want to pass arguments to a process. This is really Collection of Strings. Even you hit the problem that the underlying API wants you to pass in a Collection of parameters rather a single String - therefore you did the split. If user has a way to provide directly the collection that would be easiest from my point of view.

Again, if you are OK with that I can do the coding a pull request.

1reaction
ghusercommented, Nov 29, 2017

+1 for fixing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

argparse — Parser for command-line options, arguments and ...
The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv . The argparse module...
Read more >
command line arguments given to a C# program are parsed ...
I created a little batch file that would display the command line parameters. With your first command line, I get 1 -p 2...
Read more >
A Simple Guide To Command Line Arguments With ArgParse
ArgumentParser() initializes the parser so that you can start to add custom arguments. To add your arguments, use parser.add_argument() . Some ...
Read more >
jsonargparse — jsonargparse documentation
This package is an extension to python's argparse which simplifies parsing of configuration options from command line arguments, json configuration files ...
Read more >
argparse – Command line option and argument parsing.
The parser can then be used to process the command line arguments when your ... when the argument is encountered (including special handling...
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