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

global options with default values are missing when running actions #203

Open
johnwebbcole opened this issue Jan 8, 2021 · 0 comments
Open
Assignees

Comments

@johnwebbcole
Copy link

If you have a global option, with a default value, that value does not appear in the options object inside an action. However it does appear on the --help page.

Here is a playground example:

import { program } from "@caporal/core"


program
  .option('--foo <baz>', 'a global option', { default: 'bar', global: true })
  .command('order', 'Order command')

  .argument('<pizza-type>', 'Pizza type')
  .action(({ logger, args, options }) => {
    logger.info(JSON.stringify({ args, options }));
    logger.info('Ordering pizza %s', args.pizzaType);
  });

program.run();

Expected behavior
The global options with default values should appear in the action options object.

I'd expect: {"args":{"pizzaType":"one"},"options":{"baz": "bar"}}

Actual behavior
Here is the output from the example above:

~$ play order one
{"args":{"pizzaType":"one"},"options":{}}
Ordering pizza one

And the help, which shows the default value.

~$ play --help

  Caporal Playground 1.0.0 — Dynamicaly generated playground program

  USAGE 
  
    ▸ play <command> [ARGUMENTS...] [OPTIONS...]


  COMMANDS — Type 'play help <command>' to get some help about a command

    order                                Order command                                          

  GLOBAL OPTIONS

    -h, --help                           Display global help or command-related help.           
    -V, --version                        Display version.                                       
    --no-color                           Disable use of colors in output.                       
    -v, --verbose                        Verbose mode: will also output debug messages.         
    --quiet                              Quiet mode - only displays warn and error messages.    
    --silent                             Silent mode: does not output anything, giving no       
                                         indication of success or failure other than the exit   
                                         code.                                                  
    --foo <baz>                          a global option                                        
                                         default: "bar"          

Environment information (please complete the following information):

  • OS: Mac and in the ground
  • OS version: 10.15.7
  • Shell: zsh
  • Caporal version: 2.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