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}")]