dotnet / dotnet/command-line-api

Invoke a parent command without specifying its subcommands

Open
#1,812 9 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

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.

```csharp
using System.CommandLine;

var loadOpt = new Option("--load");
var rootCmd = new RootCommand() { loadOpt };

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

rootCmd.AddCommand(subCmd);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.