Skip to content

Add built-in example for defining a global --verbosity / -v option #2744

@abhiramch018

Description

@abhiramch018

Type of issue

Feature request / documentation enhancement

Description

System.CommandLine already supports global options, but there’s no sample showing
how to define a global --verbosity (-v) option that applies to all subcommands
and defaults to Diagnostic when specified without a value.

Suggested improvement

Add a short example to the README or samples folder demonstrating:

var verbosity = new Option<string>(
    new[] { "-v", "--verbosity" },
    "Set output verbosity (quiet, minimal, normal, detailed, diagnostic)")
{
    Arity = ArgumentArity.ZeroOrOne
};
root.AddGlobalOption(verbosity);
Why this helps

--verbosity is a standard .NET CLI pattern, so showing how to implement it helps developers align their own tools with .NET conventions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions