Beispiel #1
0
        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);
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        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;
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
 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()}");
     }
 }
Beispiel #8
0
 public PackCommand(Options options, CommandContext context)
 {
     _options = options.PackCommand;
     _rootOptions = options;
 }
Beispiel #9
0
 public ServeCommand(Options options, CommandContext context)
 {
     _options = options.ServeCommand;
     _rootOptions = options;
 }
Beispiel #10
0
 public HelpCommand(Options options, CommandContext context)
 {
     _options = options.HelpCommand;
     _rootOptions = options;
 }