Skip to content

program.exec throwing odd error and can't figure out right way to pass options #226

Open
@arsdehnel

Description

@arsdehnel

Describe the bug
I'm trying to call one command from inside another. Perhaps a weird use case but trying to have my-program wrapper call a couple child commands internally. It's working when it calls the command with no options but it's failing if I try to pass any options into the child command via program.exec( [ 'child-arg' ], options ).

To Reproduce
This is the "child" command setup:

module.exports = ( { createCommand } ) => {

    return createCommand( 'Run compliance for foo' )
        .option( '--check-only', 'Only check compliance' )
        .action( async ( { options, logger } ) => {

            console.log( 'Running compliance checks and configuration for foo' );

    } );

};

This snippet works and runs the foo command successfully.

module.exports = ( { createCommand } ) => {

    return createCommand( 'Run child commands all at once' )
        .option( '--check-only', 'Only check compliance' )
        .action( async ( { options, logger } ) => {

            program.exec( [ 'foo' ] );

    } );

};

This snippet, however, throws the error Unknown option --check-only. Did you mean --check-only ?.

module.exports = ( { createCommand } ) => {

    return createCommand( 'Run child commands all at once' )
        .option( '--check-only', 'Only check compliance' )
        .action( async ( { options, logger } ) => {

            program.exec( [ 'foo' ], options );

    } );

};

Expected behavior
The options object should be passed into the child command and applied properly.

Actual behavior
Error is thrown: Unknown option --check-only. Did you mean --check-only ?.

Environment informations (please complete the following information):

  • OS: macOS
  • OS version: 11.6
  • Shell: zsh
  • Caporal version: 2.0.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions