Skip to content

Invoke a parent command without specifying its subcommands #1812

Open
@qui8t

Description

@qui8t

In my use case, both the following invocations are expected.

$ myprog --load checkpoint.json
$ myprog process --file test.json

where the root command myprog with the subcommand process can be called without specifying a subcommand. Is this use-case currently supported in System.CommandLine?

Using a code similar to the following, I get Required command was not provided error when making the first invocation above.

using System.CommandLine;

var loadOpt = new Option<FileInfo?>("--load");
var rootCmd = new RootCommand() { loadOpt };

var fileOpt = new Option<FileInfo?>("--file");
var subCmd = new Command(name: "process") { fileOpt };

rootCmd.AddCommand(subCmd);

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions