Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty strings are parsed as arguments regardless of context #665

Open
greentore opened this issue Nov 23, 2023 · 1 comment
Open

Empty strings are parsed as arguments regardless of context #665

greentore opened this issue Nov 23, 2023 · 1 comment

Comments

@greentore
Copy link

Passing an empty string ("") to an option with a required value results in an error. In case of optional value the string is ignored and you get true instead.
Is it a bug or working as intended?

@greentore
Copy link
Author

I investigated this issue a bit more and turns out cliffy is always parsing empty strings as arguments regardless of context.

import { Command } from "jsr:@cliffy/command@^1.0.0-rc.4";

const cli = new Command()
  .arguments("[a]")
  .option(
    "-A, --A [a]",
    "A",
  )
  .action((opts, ...args) => {
    console.log(opts);
    console.log(args);
  });

cli.parse(["-A", ""]);
// { A: true }
// [ "" ]
cli.parse(["-A", " "]);
// { A: " " }
// []

An aside, but seems like short flag only options are broken at the moment. "-A [a]" resulted in name being an empty string.

@greentore greentore changed the title Empty strings are not recognized as a value for option Empty strings are parsed as arguments regardless of context Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant