2
program
  .command("split")
  .description("Split a string into substrings and display as an array")
  .argument("<string>", "string to split")
  .option("--first", "display just the first substring")
  .option("-s ,--separator <char>", "separator character", ",")
  .action((str, options) => {
  console.log(options);
  const limit = options.first ? 1 : undefined;
  console.log(str.split(options.separator, limit));
 });

-s="l" is parsed as {seperator:"=l"}

--seperator="l" is parsed as {seperator :"l"}

how to get uniform parsing either as "=l" or "l" while using both short and long flags

  • 1
    The behavior you're seeing is pretty much standard, especially for Node programs. – Pointy Nov 23 '22 at 13:29
  • For interest, coverage of patterns used by widely used implementations and POSIX standard: github.com/pkgjs/parseargs/issues/78 – shadowspawn Nov 24 '22 at 08:16

1 Answers1

1

The supported forms for specifying an option and option-argument in Commander are

serve -p 80
serve --port 80
serve -p80
serve --port=80

There is not support in Commander for making the short and long options "uniform" for the combined option and value form.

The short form comes from POSIX and GNU guidelines.

POSIX Utility Conventions

If the SYNOPSIS of a standard utility shows an option with a mandatory option-argument (as with [ -c option_argument] in the example), a conforming application shall use separate arguments for that option and its option-argument. However, a conforming implementation shall also permit applications to specify the option and option-argument in the same argument string without intervening characters.

GNU Program Argument Syntax Conventions

An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, -o foo and -ofoo are equivalent.

(I am a maintainer of Commander.)

shadowspawn
  • 3,039
  • 22
  • 26