Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command examples #115

Open
Tyrrrz opened this issue Dec 5, 2021 Discussed in #114 · 3 comments
Open

Command examples #115

Tyrrrz opened this issue Dec 5, 2021 Discussed in #114 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Tyrrrz
Copy link
Owner

Tyrrrz commented Dec 5, 2021

Discussed in #114

Originally posted by wayneyaoo December 4, 2021
Can we have concept of "Example" for each command that can be specified by the CLI author and a new section is rendered as "EXAMPLE".

I was imaging something like

[Command("verb")]
public class MyCommand : ICommand
{
    // options and parameters go here as property

    [Example]
    public (static) Example[] Examples = new [] 
        { new Example("verb --option value"), new Example("verb --anotherPositionalOption") };
}

and the examples could be rendered to another section like "EXAMPLE" when ./myapp verb -h is called.

I'm happy to contribute if this looks good. Or we can discuss.

@Tyrrrz Tyrrrz added the enhancement New feature or request label Dec 5, 2021
@Tyrrrz Tyrrrz changed the title "Examples" of command Command examples Dec 5, 2021
@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Dec 5, 2021

My reply: #114 (comment)

@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Apr 16, 2022

Note: this is better implemented as another string property on the CommandAttribute, not as a type member as visualized in the original post.

@Tyrrrz Tyrrrz added the good first issue Good for newcomers label Aug 25, 2022
@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Aug 25, 2022

Example usage:

[Command("foo", Examples = new[]
	{
		// Note: no need to add the command name here
		"--bar 42",
		"-b 42"
	}
]
public class MyCommand : ICommand
{
	// ...
}

The examples would then be shown in the "usage" section of the help text:

USAGE
  dotnet myapp.dll foo [options]
  dotnet myapp.dll foo --bar 42
  dotnet myapp.dll foo -b 42

OPTIONS
  -b|--bar          Something.
  -h|--help         Shows help text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant