Esempio n. 1
0
        public static XmlDocVisibilityLevel?ReadVisibilityOption(this ArgsReader args)
        {
            string visibility = args.ReadOption("visibility");

            switch (visibility)
            {
            case "public":
                return(XmlDocVisibilityLevel.Public);

            case "protected":
                return(XmlDocVisibilityLevel.Protected);

            case "internal":
                return(XmlDocVisibilityLevel.Internal);

            case "private":
                return(XmlDocVisibilityLevel.Private);

            case null:
                return(null);

            default:
                throw new ArgsReaderException($"Unknown visibility option: {visibility}");
            }
        }
Esempio n. 2
0
        public static string ReadNewLineOption(this ArgsReader args)
        {
            string value = args.ReadOption("newline");

            if (value == null)
            {
                return(null);
            }

            switch (value)
            {
            case "auto":
                return(null);

            case "lf":
                return("\n");

            case "crlf":
                return("\r\n");

            default:
                throw new ArgsReaderException($"Invalid new line '{value}'. (Should be 'auto', 'lf', or 'crlf'.)");
            }
        }
Esempio n. 3
0
 public static bool ReadVerifyFlag(this ArgsReader args)
 {
     return(args.ReadFlag("verify"));
 }
Esempio n. 4
0
 public static string ReadPermalinkStyle(this ArgsReader args)
 {
     return(args.ReadOption("permalink"));
 }
Esempio n. 5
0
 public static string ReadFrontMatter(this ArgsReader args)
 {
     return(args.ReadOption("front-matter"));
 }
Esempio n. 6
0
 public static bool ReadNamespacePagesFlag(this ArgsReader args)
 {
     return(args.ReadFlag("namespace-pages"));
 }
Esempio n. 7
0
 public static bool ReadQuietFlag(this ArgsReader args)
 {
     return(args.ReadFlag("quiet"));
 }
Esempio n. 8
0
 public static bool ReadHelpFlag(this ArgsReader args)
 {
     return(args.ReadFlag("help|h|?"));
 }
Esempio n. 9
0
 public static string ReadSourceOption(this ArgsReader args)
 {
     return(args.ReadOption("source"));
 }
Esempio n. 10
0
 public static bool ReadCleanFlag(this ArgsReader args)
 {
     return(args.ReadFlag("clean"));
 }
Esempio n. 11
0
 public static string ReadExternalOption(this ArgsReader args)
 {
     return(args.ReadOption("external"));
 }
Esempio n. 12
0
 public static bool ReadSkipUnbrowsableFlag(this ArgsReader args)
 {
     return(args.ReadFlag("skip-unbrowsable"));
 }
Esempio n. 13
0
 public static bool ReadObsoleteFlag(this ArgsReader args)
 {
     return(args.ReadFlag("obsolete"));
 }
Esempio n. 14
0
 public static string ReadNamespaceOption(this ArgsReader args)
 {
     return(args.ReadOption("namespace"));
 }
Esempio n. 15
0
 public static bool ReadTocFlag(this ArgsReader args)
 {
     return(args.ReadFlag("toc"));
 }
Esempio n. 16
0
 public static bool ReadDryRunFlag(this ArgsReader args)
 {
     return(args.ReadFlag("dryrun"));
 }
Esempio n. 17
0
        /// <summary>
        /// Run the command-line application.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        /// <returns>The exit code.</returns>
        public static int Run(IReadOnlyList <string> args)
        {
            try
            {
                var argsReader = new ArgsReader(args);
                if (argsReader.ReadHelpFlag())
                {
                    WriteUsage(Console.Out);
                    return(0);
                }

                var isVerify = argsReader.ReadVerifyFlag();

                var settings = new XmlDocMarkdownSettings
                {
                    NewLine         = argsReader.ReadNewLineOption(),
                    SourceCodePath  = argsReader.ReadSourceOption(),
                    RootNamespace   = argsReader.ReadNamespaceOption(),
                    IncludeObsolete = argsReader.ReadObsoleteFlag(),
                    SkipUnbrowsable = argsReader.ReadSkipUnbrowsableFlag(),
                    VisibilityLevel = argsReader.ReadVisibilityOption(),
                    ShouldClean     = argsReader.ReadCleanFlag(),
                    IsQuiet         = argsReader.ReadQuietFlag(),
                    IsDryRun        = isVerify || argsReader.ReadDryRunFlag(),
                    FrontMatter     = argsReader.ReadFrontMatter(),
                    PermalinkStyle  = argsReader.ReadPermalinkStyle(),
                    GenerateToc     = argsReader.ReadTocFlag(),
                    TocPrefix       = argsReader.ReadTocPrefix(),
                    NamespacePages  = argsReader.ReadNamespacePagesFlag(),
                };

                var    externalDocs = new List <ExternalDocumentation>();
                string?externalOption;
                while ((externalOption = argsReader.ReadExternalOption()) != null)
                {
                    externalDocs.Add(new ExternalDocumentation {
                        Namespace = externalOption
                    });
                }
                if (externalDocs.Count != 0)
                {
                    settings.ExternalDocs = externalDocs;
                }

                var inputPath = argsReader.ReadArgument();
                if (inputPath == null)
                {
                    throw new ArgsReaderException("Missing input path.");
                }

                var input = File.Exists(inputPath)
                                        ? new XmlDocInput {
                    AssemblyPath = inputPath
                }
                                        : new XmlDocInput {
                    Assembly = Assembly.Load(inputPath)
                };

                var outputPath = argsReader.ReadArgument();
                if (outputPath == null)
                {
                    throw new ArgsReaderException("Missing output path.");
                }

                argsReader.VerifyComplete();

                var result = XmlDocMarkdownGenerator.Generate(input, outputPath, settings);

                foreach (var message in result.Messages)
                {
                    Console.WriteLine(message);
                }

                return(isVerify && result.Added.Count + result.Changed.Count + result.Removed.Count != 0 ? 1 : 0);
            }
            catch (Exception exception)
            {
                if (exception is ArgsReaderException)
                {
                    Console.Error.WriteLine(exception.Message);
                    Console.Error.WriteLine();
                    WriteUsage(Console.Error);
                    return(2);
                }
                else if (exception is ApplicationException || exception is IOException || exception is UnauthorizedAccessException)
                {
                    Console.Error.WriteLine(exception.Message);
                    return(3);
                }
                else
                {
                    Console.Error.WriteLine(exception.ToString());
                    return(3);
                }
            }
        }
Esempio n. 18
0
 public static string ReadTocPrefix(this ArgsReader args)
 {
     return(args.ReadOption("toc-prefix"));
 }