Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Can't pass an empty string flag #55

Open
dkundel opened this issue Jul 12, 2019 · 2 comments
Open

Can't pass an empty string flag #55

dkundel opened this issue Jul 12, 2019 · 2 comments

Comments

@dkundel
Copy link

dkundel commented Jul 12, 2019

Hi there,

I have an issue that faced in https://github.com/twilio-labs/plugin-serverless where present string flags without any value don't work.

For example, this doesn't work:

twilio serverless:start --inspect

This works however:

twilio serverless:start --inspect=""

The problem seems to be here because if nothing else is being passed the last value will be undefined. If something else is passed it will be turned into the value.

For now the workaround for me is to add an empty string to the back of argv but this doesn't seem to be a good solution.

Update: in fact this doesn't even work. The fix instead is a documentation one for now to mention to pass an empty string

@dkundel dkundel changed the title Can't pass an empty string flag as last argument Can't pass an empty string flag Jul 12, 2019
@xavdid
Copy link

xavdid commented Aug 1, 2019

This seems like intended behavior, no? If it's a boolean flag, it should have no value. if it's a string flag, it should have a value. I'm not sure they support a flag that acts as both.

@dkundel
Copy link
Author

dkundel commented Aug 2, 2019

They currently don't support one but it's common behavior. Example from Node.js: https://nodejs.org/api/cli.html#cli_inspect_host_port

In yargs the behavior is the following for string flags:

  • flag not passed => default value if available or undefined
  • flag passed but no value => '' aka empty string
  • flag passed with value => set to value

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants