c4spar / deno-cliffy

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
https://cliffy.io
MIT License
929 stars 65 forks source link

Empty strings are parsed as arguments regardless of context #665

Open greentore opened 10 months ago

greentore commented 10 months ago

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 commented 5 months ago

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.