From 639861b2445cf2c71001cd7529aafe227db2fdc5 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Thu, 18 May 2023 10:07:09 +0800 Subject: [PATCH] fix: array options not bound to command line args (#8784) --- src/docfx/Extensions/ArrayOptionConverter.cs | 25 ++++++++++++++++++++ src/docfx/Models/BuildCommandOptions.cs | 4 ++++ src/docfx/Models/PdfCommandOptions.cs | 1 + 3 files changed, 30 insertions(+) create mode 100644 src/docfx/Extensions/ArrayOptionConverter.cs diff --git a/src/docfx/Extensions/ArrayOptionConverter.cs b/src/docfx/Extensions/ArrayOptionConverter.cs new file mode 100644 index 00000000000..accad4f867a --- /dev/null +++ b/src/docfx/Extensions/ArrayOptionConverter.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.ComponentModel; +using System.Globalization; + +namespace Microsoft.DocAsCode; + +internal class ArrayOptionConverter : TypeConverter +{ + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + return value is string && (destinationType == typeof(IEnumerable) || destinationType == typeof(string[])); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + if (value is string str) + { + return str.Split(',', StringSplitOptions.RemoveEmptyEntries); + } + + return base.ConvertFrom(context, culture, value); + } +} diff --git a/src/docfx/Models/BuildCommandOptions.cs b/src/docfx/Models/BuildCommandOptions.cs index 8dca99c0d67..de5c8b9a9de 100644 --- a/src/docfx/Models/BuildCommandOptions.cs +++ b/src/docfx/Models/BuildCommandOptions.cs @@ -19,14 +19,17 @@ internal class BuildCommandOptions : LogOptions [Description("Specify the urls of xrefmap used by content files.")] [CommandOption("-x|--xref")] + [TypeConverter(typeof(ArrayOptionConverter))] public IEnumerable XRefMaps { get; set; } [Description("Specify the template name to apply to. If not specified, output YAML file will not be transformed.")] [CommandOption("-t|--template")] + [TypeConverter(typeof(ArrayOptionConverter))] public IEnumerable Templates { get; set; } [Description("Specify which theme to use. By default 'default' theme is offered.")] [CommandOption("--theme")] + [TypeConverter(typeof(ArrayOptionConverter))] public IEnumerable Themes { get; set; } [Description("Host the generated documentation to a website")] @@ -79,6 +82,7 @@ internal class BuildCommandOptions : LogOptions [Description("Set the order of post processors in plugins")] [CommandOption("--postProcessors")] + [TypeConverter(typeof(ArrayOptionConverter))] public IEnumerable PostProcessors { get; set; } [Description("If set to true, docfx does not dereference (aka. copy) file to the output folder, instead, it saves a link_to_path property inside mainfiest.json to indicate the physical location of that file.")] diff --git a/src/docfx/Models/PdfCommandOptions.cs b/src/docfx/Models/PdfCommandOptions.cs index d2eba3f1377..fbf22e3e604 100644 --- a/src/docfx/Models/PdfCommandOptions.cs +++ b/src/docfx/Models/PdfCommandOptions.cs @@ -51,6 +51,7 @@ internal class PdfCommandOptions : BuildCommandOptions [Description("Specify the toc files to be excluded")] [CommandOption("--excludedTocs")] + [TypeConverter(typeof(ArrayOptionConverter))] public IEnumerable ExcludedTocs { get; set; } [Description("Specify the base path to generate external link, {host}/{locale}/{basePath}")]