You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a BaseArgs class and a bunch of derived specialized argument classes. The BaseArgs class has an Enum for the action to be invoked. Actions are complex enough to warrant their own specific classes to hold their args.
I was hoping to use Args.Parse<BaseArgs>(args) to get the Action enum, then based on the result, use Args.Parse<DerivedArgs>(args), since DerivedArgs's type corresponds to the Action I got from the previous call. Is there a way to do this, or would I have to just try to parse as each derived class and catch the exceptions myself?
The text was updated successfully, but these errors were encountered:
I would not base the actions off of an enum. Here's the pattern I'd recommend. It lets you model your action specific options as classes, while letting PowerArgs invoke the right action for you so you don't have to base it off of a switch.
[ArgExceptionBehavior(ArgExceptionPolicy.StandardExceptionHandling,ShowTypeColumn=false,ShowPossibleValues=true)]
public class Commands
{
// global options
[ArgShortcut("-q"), ArgDescription("Don't show verbose output")]
public bool Quiet { get; set; }
[ArgShortcut("-?"), ArgDescription("Displays this help"), HelpHook(ShowTypeColumn=false, ShowPossibleValues=true)]
public bool Help { get; set; }
[NonInteractiveIndicator, ArgDescription("Indicates that the REPL should not be used")]
public bool NoREPL { get; set; }
[ArgActionMethod,ArgDescription("Command1 help here")]
public void Command1(Command1Args command)
{
command.Invoke();
}
[ArgActionMethod,ArgDescription("Command2 help here")]
public void Command2(Command2Args command)
{
command.Invoke();
}
}
I have a
BaseArgs
class and a bunch of derived specialized argument classes. TheBaseArgs
class has an Enum for the action to be invoked. Actions are complex enough to warrant their own specific classes to hold their args.I was hoping to use
Args.Parse<BaseArgs>(args)
to get the Action enum, then based on the result, useArgs.Parse<DerivedArgs>(args)
, sinceDerivedArgs
's type corresponds to the Action I got from the previous call. Is there a way to do this, or would I have to just try to parse as each derived class and catch the exceptions myself?The text was updated successfully, but these errors were encountered: