private static object GetSubOption(Options options, string verb) { if (options == null || string.IsNullOrEmpty(verb)) return null; var property = typeof(Options).GetProperties().Where(s => s.GetCustomAttribute<VerbOptionAttribute>()?.LongName.ToLowerInvariant() == verb).FirstOrDefault(); if (property == null) return null; return property.GetValue(options); }
public ExportCommand(Options options, CommandContext context) { _options = options.ExportCommand; if (_options.IsHelp) { _helpMessage = HelpTextGenerator.GetHelpMessage(options, "export"); } else { options.MetadataCommand = _options; _metadataCommand = new MetadataCommand(options, context); } }
public BuildCommand(Options options, CommandContext context) { var buildCommandOptions = options.BuildCommand; if (buildCommandOptions.IsHelp) { _helpMessage = HelpTextGenerator.GetHelpMessage(options, "build"); } else { Config = MergeConfig(GetConfigFromOptions(buildCommandOptions), context); } if (!string.IsNullOrWhiteSpace(buildCommandOptions.Log)) Logger.RegisterListener(new ReportLogListener(buildCommandOptions.Log)); if (buildCommandOptions.LogLevel.HasValue) Logger.LogLevelThreshold = buildCommandOptions.LogLevel.Value; }
public MetadataCommand(Options options, CommandContext context) { var metadataCommandOptions = options.MetadataCommand; if (metadataCommandOptions.IsHelp) { _helpMessage = HelpTextGenerator.GetHelpMessage(options, "metadata"); } else { Config = MergeConfig(GetConfigFromOptions(metadataCommandOptions), context); InputModels = GetInputModels(Config); } if (!string.IsNullOrWhiteSpace(metadataCommandOptions.Log)) Logger.RegisterListener(new ReportLogListener(metadataCommandOptions.Log)); if (metadataCommandOptions.LogLevel.HasValue) Logger.LogLevelThreshold = metadataCommandOptions.LogLevel.Value; }
public static string GetHelpMessage(Options options, string verb = null) { if (!string.IsNullOrEmpty(verb)) { var subOption = GetSubOption(options, verb); if (subOption == null) { HelpText.AddPreOptionsLine("Unknown command: " + verb); } else { HelpText.AddPreOptionsLine(Environment.NewLine); HelpText.AddPreOptionsLine("Usage: docfx " + verb); HelpText.AddOptions(subOption); } } return HelpText; }
private static ParseResult TryGetOptions(string[] args, out Options options) { options = new Options(); string invokedVerb = null; object invokedVerbInstance = null; if (args.Length == 0) { return ParseResult.SuccessResult; } if (!Parser.Default.ParseArguments(args, options, (s, o) => { invokedVerb = s; invokedVerbInstance = o; })) { if (!Parser.Default.ParseArguments(args, options)) { var text = HelpTextGenerator.GetHelpMessage(options); return new ParseResult(ResultLevel.Error, text); } else { return ParseResult.SuccessResult; } } else { try { options.CurrentSubCommand = (CommandType)Enum.Parse(typeof(CommandType), invokedVerb, true); } catch { return new ParseResult(ResultLevel.Error, $"{invokedVerb} subcommand is not currently supported."); } } return ParseResult.SuccessResult; }
private static ParseResult Exec(Options options, RunningContext context) { ICommand command; try { command = CommandFactory.GetCommand(options); } catch (Exception e) { return new ParseResult(ResultLevel.Error, $"Fails to get config file: {e.Message}"); } try { return command.Exec(context); } catch (Exception e) { return new ParseResult(ResultLevel.Error, $"Error running program: {e.ToString()}"); } }
public PackCommand(Options options, CommandContext context) { _options = options.PackCommand; _rootOptions = options; }
public ServeCommand(Options options, CommandContext context) { _options = options.ServeCommand; _rootOptions = options; }
public HelpCommand(Options options, CommandContext context) { _options = options.HelpCommand; _rootOptions = options; }