-
Notifications
You must be signed in to change notification settings - Fork 481
How to implement countable flags? Ref. -vvv for "triple verbosity" #523
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
Comments
Switches can be merged together:
Using the following Option class class Options
{
[Option('v')]
public string Verbose { get; set; }
} The commandline:
|
Thanks! =) |
Oh wait, I was a bit hasty, sorry!
Is that a necessity? It's not possible to give the flag Edit: To clarify, I'm under the impression now that what I quoted of your answer is something decided by the framework, not just an implementation detail you suggested. |
Verbose is defined as string not bool (so it's a Scalar option not a boolean Switch ) to accept string values as described above.
Do you mean: in that case Verbose can be integer. |
Just to clarify (but I think we understand each other now):
That's as easy as; class Options
{
[Option(
'v',
MetaName = "verbosity")]
public uint Verbosity { get; set; }
} ? |
In that case, verbose will be uint : v1 or v2 or v3 and no way to map against -v or -vv or -vvv enum VerboseEnum
{
v =1,
vv,
vvv
}
class Options
{
[Option(
'v',
MetaName = "verbosity",
Default=VerboseEnum.v)]
public VerboseEnum Verbosity { get; set; }
} The command can be:
That is Quad verbosity not a triple ;) :) Edit
|
I'm still not getting it =/ Here's my code;namespace Slackbot
{
// Std libs
using System;
// External libs
using CommandLine;
public class Program
{
protected enum VerbosityEnum
{
v = 1,
vv = 2,
vvv = 3,
}
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>( options =>
{
Console.WriteLine(
$"Current Arguments: -v {options.Verbosity}"
+ "\nQuick start example.");
});
}
protected class Options
{
[Option(
'v',
HelpText = "Verbosity level.",
Default=VerbosityEnum.v)]
public uint Verbosity { get; set; }
}
}
} Here's my output from testing;-> $ dotnet run -- -vv
program.cs(22,37): warning SA1008: Opening parenthesis should not be followed by a space. [/home/x10an14/Documents/project/project.csproj]
program.cs(13,13): warning SA1300: Element 'v' should begin with an uppercase letter [/home/x10an14/Documents/project/project.csproj]
program.cs(14,13): warning SA1300: Element 'vv' should begin with an uppercase letter [/home/x10an14/Documents/project/project.csproj]
program.cs(15,13): warning SA1300: Element 'vvv' should begin with an uppercase letter [/home/x10an14/Documents/project/project.csproj]
Hello World!
slackbot 1.0.0
Copyright (C) 2019 slackbot
ERROR(S):
Option 'v' is defined with a bad format.
Error setting value to option 'v': Check if Option or Value attribute values are set properly for the given type.
-v (Default: v) Verbosity level.
--help Display this help screen.
--version Display version information.
-> $ dotnet run --
Hello World!
slackbot 1.0.0
Copyright (C) 2019 slackbot
ERROR(S):
Error setting value to option 'v': Check if Option or Value attribute values are set properly for the given type.
-v (Default: v) Verbosity level.
--help Display this help screen.
--version Display version information.
-> $ dotnet run -- -v
Hello World!
slackbot 1.0.0
Copyright (C) 2019 slackbot
ERROR(S):
Option 'v' has no value.
Error setting value to option 'v': Check if Option or Value attribute values are set properly for the given type.
-v (Default: v) Verbosity level.
--help Display this help screen.
--version Display version information.
-> $ |
Here's a reference of how Rust's 1: https://github.com/TeXitoi/structopt |
Edit: |
rename "term limit" to results limit, or else add both ngrams limit and results limit this is also per brad's feedback |
This issue seems to have been fixed by #684 You need to set var parser = new Parser(with =>
{
with.GetoptMode = true;
});
...
class Options
{
[Option('v', FlagCounter = true, HelpText = "Verbosity level: v or vv, vvv or vvvv")]
public int Verbosity { get; set; }
} Online demo: https://dotnetfiddle.net/E8Q3sL |
I'm not sure whether or not what I describe is part of the GNU getopt standard.
But
ssh
is a good example for what I'm trying to do.Anyone using Github can perform the following (as long as they've set-up SSH keys):
And....
Long SSH example output
So in short, I can supply
-v
,-vv
, or-vvv
to thessh
command, and get increasing levels of verbosity.I enjoy the opportunity to supply
-v (--verbose)
and-q (--quiet)
flags in CLIs I implement.The text was updated successfully, but these errors were encountered: