public void Parse(string[] args) { var first = args.FirstOrDefault() ?? string.Empty; try { var descriptors = CommandDescriptor.GetMemberDescriptors(this.Instance).ToArray(); var parser = new ParseDescriptor(descriptors, args); parser.SetValue(this.Instance); } catch (Exception e) { if (first == string.Empty) { throw new CommandParseException(CommandParseError.Empty, args, true, e); } if (first == this.HelpName) { throw new CommandParseException(CommandParseError.Help, args, true, e); } if (first == this.VersionName) { throw new CommandParseException(CommandParseError.Version, args, true, e); } throw e; } }
protected virtual void PrintUsage(CommandUsage usage) { var descriptors = CommandDescriptor.GetMemberDescriptors(this); var printer = new CommandMemberUsagePrinter(this.ExecutionName, this, this.Aliases) { Usage = usage, IsAnsiSupported = this.IsAnsiSupported }; printer.Print(this.Out, descriptors.ToArray()); }
private string[] GetCompletion(ICommand item, string[] args, string find) { if (item is ICommandCompletor completor) { var members = CommandDescriptor.GetMemberDescriptors(item); var context = CommandCompletionContext.Create(item, members, args, find); if (context is CommandCompletionContext completionContext) { var completion = completor.GetCompletions(completionContext); if (completion != null) { return(completion); } } else if (context is string[] completions) { return(completions); } } return(null); }
protected CommandMemberDescriptor GetDescriptor(string propertyName) { return(CommandDescriptor.GetMemberDescriptors(this)[propertyName]); }