Issue by UmairB
_Thursday Apr 27, 2017 at 20:53 GMT_
_Originally opened as https://github.com/gsscoder/commandline/issues/442_
Is it possible to do something like the following?
myapp --interactive
myapp --service
myapp import --file C:\test.xml --model ModelOne
So I want the option of using the import verb, if one is supplied, --file and --model are required. If not, then check if --interactive or --service were supplied.
I tried something like the following
class Options
{
[Option('i'...
public bool Interactive { get; set; }
[Option('s'...
public bool Service { get; set; }
public ImportOptions Import { get; set; }
[Verb("import"...
public class ImportOptions
{
...
}
}
I am using 2.1.1-beta on .net standard.
Comment by Scottz0r
_Saturday Apr 29, 2017 at 22:18 GMT_
This is possible by making "interactive" and "service" verbs. Make the target classes empty classes, and add the double dash to the verb name:
```c#
class Options
{
[Verb("--interactive")]
public class Interactive
{
}
[Verb("--service")]
public class Service
{
}
[Verb("import")]
public class ImportOptions
{
[Option("file", Required = true)]
public string File { get; set; }
[Option("model", Required = true)]
public string Model { get; set; }
}
}
class Program
{
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments
.WithParsed
.WithParsed
.WithParsed
}
}
```
Comment by gsscoder
_Friday May 12, 2017 at 06:49 GMT_
Hi all,
if possible I'd suggest to make _interactive_ and _service_ normal verbs (without dashes), if possible.
At the moment when using verbs none global switch is supported, but maybe in future.
Thanks for posting. :)
Most helpful comment
_Saturday Apr 29, 2017 at 22:18 GMT_
This is possible by making "interactive" and "service" verbs. Make the target classes empty classes, and add the double dash to the verb name:
```c#
class Options
{
[Verb("--interactive")]
public class Interactive
{
}
class Program(args)(opt => Console.WriteLine("Interactive mode"))(opt => Console.WriteLine("Service mode"))(opt => Console.WriteLine($"Import mode: {opt.File} - {opt.Model}"));
{
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments
.WithParsed
.WithParsed
.WithParsed
}
}
```