Ejemplo 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}");
            }
        }
Ejemplo 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'.)");
            }
        }
Ejemplo n.º 3
0
 public static bool ReadVerifyFlag(this ArgsReader args)
 {
     return(args.ReadFlag("verify"));
 }
Ejemplo n.º 4
0
 public static string ReadPermalinkStyle(this ArgsReader args)
 {
     return(args.ReadOption("permalink"));
 }
Ejemplo n.º 5
0
 public static string ReadFrontMatter(this ArgsReader args)
 {
     return(args.ReadOption("front-matter"));
 }
Ejemplo n.º 6
0
 public static bool ReadNamespacePagesFlag(this ArgsReader args)
 {
     return(args.ReadFlag("namespace-pages"));
 }
Ejemplo n.º 7
0
 public static bool ReadQuietFlag(this ArgsReader args)
 {
     return(args.ReadFlag("quiet"));
 }
Ejemplo n.º 8
0
 public static bool ReadHelpFlag(this ArgsReader args)
 {
     return(args.ReadFlag("help|h|?"));
 }
Ejemplo n.º 9
0
 public static string ReadSourceOption(this ArgsReader args)
 {
     return(args.ReadOption("source"));
 }
Ejemplo n.º 10
0
 public static bool ReadCleanFlag(this ArgsReader args)
 {
     return(args.ReadFlag("clean"));
 }
Ejemplo n.º 11
0
 public static string ReadExternalOption(this ArgsReader args)
 {
     return(args.ReadOption("external"));
 }
Ejemplo n.º 12
0
 public static bool ReadSkipUnbrowsableFlag(this ArgsReader args)
 {
     return(args.ReadFlag("skip-unbrowsable"));
 }
Ejemplo n.º 13
0
 public static bool ReadObsoleteFlag(this ArgsReader args)
 {
     return(args.ReadFlag("obsolete"));
 }
Ejemplo n.º 14
0
 public static string ReadNamespaceOption(this ArgsReader args)
 {
     return(args.ReadOption("namespace"));
 }
Ejemplo n.º 15
0
 public static bool ReadTocFlag(this ArgsReader args)
 {
     return(args.ReadFlag("toc"));
 }
Ejemplo n.º 16
0
 public static bool ReadDryRunFlag(this ArgsReader args)
 {
     return(args.ReadFlag("dryrun"));
 }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 18
0
 public static string ReadTocPrefix(this ArgsReader args)
 {
     return(args.ReadOption("toc-prefix"));
 }