ntl icon indicating copy to clipboard operation
ntl copied to clipboard

[Q] How to pass the arguments?

Open stagefright5 opened this issue 3 years ago • 11 comments

How to pass arguments for the scripts. For example,

npm run abc -- a1=v1 a2=v2

How do I do this when executing a script through ntl?

stagefright5 avatar Sep 14 '20 19:09 stagefright5

There's no way to do that currently - That said I would love to hear some ideas on how to better implement forwarding arguments to scripts as I def think it would make sense to support it 😊

ruyadorno avatar Sep 28 '20 20:09 ruyadorno

Hi, I just saw your reply. I would be happy to contribute but, I am quite busy till this month's end. I will try to do something over the weekend. Thanks for considering.

stagefright5 avatar Oct 12 '20 15:10 stagefright5

I gave it some thought and I think a very good UX for this would be something like:

$ ntl -i
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ start › node scripts/start.js
   test › node test/test.js
   menu › ntl -i

and then allowing users to enter an edit mode by hitting a specific key, let's say E:

$ ntl -i
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ EDITING: start › node scripts/start.js --build▌
   test › node test/test.js
   menu › ntl -i

Then once they hit ENTER we run this modified script instead, we could even go a step further and save it to the history of commands so that if when you run nt you run that same last command you just tweaked, also add some aliases to the ntl menu that will maybe be ephemeral to the duration of that session (idk)? Following up from the previous example, showing a menu like this the next time they run ntl:

$ ntl -i
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ start(1) › node scripts/start.js --build
     start › node scripts/start.js
      test › node test/test.js
      menu › ntl -i

I realize this might be a bit too much and even require some playing with Inquirer.js internals but I just wanted to lay out the ideas I've had 😊 I'm still open to suggestions, feedback and will consider any contribution you want to submit 😄

ruyadorno avatar Oct 23 '20 20:10 ruyadorno

I need this functionality too. I suggest next solution. Run ntl with argument ntl --argument or ntl -a. After run we choice task, hit Enter and type arguments for the script.

Normal mode:

$ ntl
⬢  Node Task List
? Select a task to run: (Use arrow keys or type to search)
❯ first:script
  second:script

With arguments mode:

$ ntl --argument
⬢  Node Task List
? Select a task to run: (Use arrow keys or type to search)
❯ first:script
  second:script
? Type argument for first:script: --argument foo

> running: first:script --argument foo

I think the idea is clear.

p. s.: Sorry for my english

sergeyblohin avatar Dec 15 '20 12:12 sergeyblohin

thank you so much @sergeyblohin! YES, your idea is clear and I think it's even better than what I previously proposed!

Having a second prompt is not only much easier to implement but also probably more intuitive for the majority of users 😊 I also think having an argument (such as --argument and -a) is better, although I still think supporting a magic key (such as E) can also be very helpful.

I already have a local branch started and will probably have some time to wrap up work on it soon 😄

ruyadorno avatar Dec 15 '20 16:12 ruyadorno

i thought it would be cool to add the required params next to the ntl.descriptions in the project.json, so ntl could ask ( pompt for each one like @sergeyblohin mentioned) for the param by showing its name:

ntl.parameters {
"start": ["--ip", "-p", "-x"]
}

BananaAcid avatar Jan 07 '21 02:01 BananaAcid

@BananaAcid that looks a little bit more evolved than what I'm planning to land at first but I can see the value and maybe we can follow up with something similar to that in the future.

It's been hard to find the time to wrap this up but I would like to provide some updates to anyone still keeping an eye on this, I have a working version of the second prompt as proposed by @sergeyblohin which for now only allows editing the arguments when pressing e (I personally find this more useful since I often only remember I wanted to edit an arg once I see the interface).

To give it a try now, install from the development branch:

$ npm install -g ruyadorno/ntl#task-editing

It would be awesome to gather some feedback on it before shipping 😊

ruyadorno avatar Feb 19 '21 03:02 ruyadorno

Any updates on this?

trsrm avatar Dec 26 '21 22:12 trsrm

for now I'd appreciate any feedback from folks with different environments, you can give it a quick try using npx:

$ npx ruyadorno/ntl#task-editing

but ideally before shipping I'd also like to add support to cli arguments as @sergeyblohin suggested previously

ruyadorno avatar Jan 10 '22 23:01 ruyadorno

for now I'd appreciate any feedback from folks with different environments, you can give it a quick try using npx:

$ npx ruyadorno/ntl#task-editing

but ideally before shipping I'd also like to add support to cli arguments as @sergeyblohin suggested previously

I am not sure, what feature is new and how to test it - could you give an example?

BananaAcid avatar Jan 27 '22 18:01 BananaAcid

I am not sure, what feature is new and how to test it - could you give an example?

For now the main thing there is an "Edit script" interface that aims to solve the problem stated at the origin of this thread (being able to pass arguments to scripts), to use it you simply hit (e) when the selector is over the item you desired to pass arguments to in the list.

ruyadorno avatar Jan 31 '22 18:01 ruyadorno