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

Unexpected behavior for (global) options #194

Open
beorn opened this issue Aug 22, 2020 · 0 comments
Open

Unexpected behavior for (global) options #194

beorn opened this issue Aug 22, 2020 · 0 comments
Assignees

Comments

@beorn
Copy link

beorn commented Aug 22, 2020

Hi, I'm trying to implement sub-commands and running into some unexpected issues with global options.

import { program } from "@caporal/core"

program
  //.option("-B <path>", "Required <path>")
  .option("-C <path>", "Required <path>", { global: true })
  .option("-D <path>", "Required <path>", {
    global: true,
    validator: program.STRING,
  })

  .command("test", "Test command")
  .action(({ args, options }) => console.log(options))

program.run()

Given the above program, these are the behaviors that I think is unexpected:

1

% myprog -C
error: Unknown command -C.

I was expected it to parse -C as a global option and either complain about missing required argument for option, <path>, or complain about missing command.

2

% myprog -C .
# or this:
% myprog -C . test
error: Unknown command -C.

Similarly, I was expecting this to be parsed as an option, not a command.

3

% myprog test -C
{ C: true }

I was expecting it to complain about missing required argument <path> for option C.

4

% myprog test -D
{ D: true }

Similarly, I was expecting it to complain about the argument for D not being of type string.

Also, shouldn't validators always be run for options with default values? If for example the default value is a the current directory ., a validator could check that the directory is readable/writable, etc.

5

If you uncomment the line with .option("-B") then myprog -h will no longer show the commands, only the options. Shouldn't both be shown?

Environment:

  • @caporal/core v2.0.2
  • ts-node v8.5.4
  • node v12.18.3
  • typescript v4.0.2
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

2 participants