Skip to content

Consider Supporting CliCommand, CliOption, CliArgument on methods and method parameters #33

@lawrencek76

Description

@lawrencek76

While working on converting an app to use command-line I discovered that it would be very convenient if this was also a supported syntax.

I tried to define some of the behavers that would be nice for the generator to support on functions below.

[CliCommand()]
internal class FunCommand
{
    [CliCommand()]
    public void RunFunction1(FileInfo inputFile, DriveType driveType = DriveType.Fixed)
    {
        Console.WriteLine($"First parameter by default is an Arg: {inputFile}");
        Console.WriteLine($"Second parameter by default is an option: {driveType}");
        Console.WriteLine("Running fun function1");
    }

    [CliCommand()]
    public void RunFunction2(FileInfo inputFileOpt, DriveType driveTypeArg = DriveType.Fixed)
    {
        Console.WriteLine($"First parameter is set to option by opt suffix on param name: {inputFileOpt}");
        Console.WriteLine($"Second parameter is set to argument by arg suffix on param name: {driveTypeArg}");
        Console.WriteLine("Running fun function2");
    }

    [CliCommand()]
    public void RunFunction3([CliOption()] string name)
    {
        Console.WriteLine($"Full control of param mapping by using the existing attributes on param: {name}");
        Console.WriteLine("Running fun function3");
    }

    [CliCommand()]
    public void RunFunctionFlag(bool flag)
    {
        Console.WriteLine($"bool is always treated as a option by default: {flag}");
        Console.WriteLine("Running fun function-flag");
    }

    [CliCommand(Name="FunctionNumber")]
    public void RunFunction3(int number)
    {
        Console.WriteLine($"if multiple functions in the same method group are clicommands then names will have to be provided to disambiguate them: {number}");
        Console.WriteLine("Running fun function-number");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions