args-parser icon indicating copy to clipboard operation
args-parser copied to clipboard

Improvement: Does not work for '-m message'

Open vipulvyas opened this issue 2 years ago • 10 comments

Today i was searching for argument parser and I got args-parser and i also have same thinking like why it not working like -m message . have you any status like any one working on it or not. If not then i am interested in it to build this. In current scenario syntax is must -m=message . it will also not work in -m = message. so it is better if we can make as -m message . Standard way for arg is -m<space><message>.

node script.js -m message

let me know if i can work on it. waiting for your response.

vipulvyas avatar May 01 '22 14:05 vipulvyas

@eveningkid @bitdeli-chef @ZitRos @NiclasThobaben what you think about this?

vipulvyas avatar May 03 '22 11:05 vipulvyas

Fine for me (I agree that's a standard way of passing arguments and maybe the library should support it). Up to a library maintainer.

nikitaeverywhere avatar May 03 '22 15:05 nikitaeverywhere

You are right it is up to library maintainer and we can make good documentation for it rather then change of it. And also if we change it then user also have to know about it because it is hard to run with legacy code in this case.

vipulvyas avatar May 08 '22 06:05 vipulvyas

Sounds like a good idea to me. It should not break projects using the library though. So -m message should then be the same as -m=message. But what about -m = message? Should it result into { m: '=' } ( which would probably be the most trivial implementation) or { m: 'message' } (which would have to be handled)?

So i wouldn't make it the standard way, rather an alternative.

It's up to @eveningkid though.

NiclasThobaben avatar May 08 '22 17:05 NiclasThobaben

Hi all,

Thanks for raising this question, you really have a good point here :)

  • I agree that -m message should be supported
  • Turning -m x into -m=x as suggested by @NiclasThobaben seems best to avoid lib to break wherein use
  • -m = x should result to m: = to be consistent with other CLIs

@vipulvyas if you want to work on a PR for this, I'll be happy to review it once ready

Just some piece of advice: make sure to thoroughly test this with all the use cases you can think of

Also, I'm sure that anyone here would be very competent to get us to a clean solution!

Keep us in touch, Vipul!

eveningkid avatar May 09 '22 04:05 eveningkid

@NiclasThobaben @eveningkid okay so -m = message should result to { m: 'message' } right ?

just approve this and i will start.

vipulvyas avatar May 11 '22 09:05 vipulvyas

As mentioned before, -m = message should result to { m: '=' }

You can try this with git commit -m = message and see that you'll get an error

So just going this way to keep it consistent with usual CLI behavior

eveningkid avatar May 12 '22 01:05 eveningkid

> node sample.js -m = message
error: invalid syntax!!
syntax: node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek==
for more visit https://www.npmjs.com/package/args-parser

is this looks good to you ? @eveningkid

vipulvyas avatar May 15 '22 05:05 vipulvyas

Do you mind creating a PR referencing this issue?

We can take the discussion from there, based on your implementation

eveningkid avatar May 15 '22 08:05 eveningkid

PR: https://github.com/eveningkid/args-parser/pull/8

vipulvyas avatar May 15 '22 16:05 vipulvyas