public int Run() { try { var a = new Args(this.Arguments); if (OnException != null) { a.OnException = (e) => { return(this.OnException(e)); }; } var entryAssembly = Assembly.GetCallingAssembly(); var programName = this.Application.GetType().Assembly.GetName().Name; var rootCommand = ObjectCommand.Create(programName, ObjectProvider.Create(new Starter(this.Application, a))); return(rootCommand.Invoke(a)); } catch (ParseError ex) { Console.Error.WriteLine(ex.Message); return(-1); } catch (Exception ex) { Console.Error.WriteLine(ex); return(-1); } }
public static ICommand AddHelp(this ObjectCommand command) { var help = new HelpOption(); command.CommandSource = command.CommandSource.Concat(new ObjectCommandSource( null, ObjectProvider.Create(help.GetType(), () => help) )); help.Command = command; return(command); }
public static Maybe <ICommand> Create(ICommand parent, IObjectProvider containingObject, MethodInfo method, IEnumerable <IOption> inheritedOptions) { if (inheritedOptions == null) { throw new ArgumentNullException(nameof(inheritedOptions)); } return(method .GetUsage() .Select(usage => { var help = new HelpOption(); var helpCommand = new ObjectCommandSource(null, ObjectProvider.Create(help)); var c = new MethodCommand(parent, containingObject, method, helpCommand.Options.Concat(inheritedOptions)); help.Command = c; return (ICommand)c; })); }