Skip to content

Top level command action does not work. #978

@negiDharmendra

Description

@negiDharmendra

When a CLI has sub-commands. Commander does not invoke top-level command action when any of the sub-command is not provided.

Example: demo.js

#! /usr/bin/env node

const program = require('commander');

program
   .option('-l, --log-level <logLevel>', 'Set log level')
   .action( function() {
           console.log('Executing top-level command ');
    });

program
   .command('dummy-command')
   .action(function () {
          console.log('Executing sub command ');
    });
  • When I run demo dummy-command everything works as expected and it prints Executing sub command on the stdout.
  • When I run demo it does not print **Executing top-level command ** on the stdout.

Is there a way to get this working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions