Skip to content

Commit

Permalink
fix: array options not bound to command line args (#8784)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored May 18, 2023
1 parent 411bd6d commit f2f31fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/docfx/Extensions/ArrayOptionConverter.cs
Original file line number Diff line number Diff line change
@@ -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<string>) || 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);
}
}
4 changes: 4 additions & 0 deletions src/docfx/Models/BuildCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> Templates { get; set; }

[Description("Specify which theme to use. By default 'default' theme is offered.")]
[CommandOption("--theme")]
[TypeConverter(typeof(ArrayOptionConverter))]
public IEnumerable<string> Themes { get; set; }

[Description("Host the generated documentation to a website")]
Expand Down Expand Up @@ -79,6 +82,7 @@ internal class BuildCommandOptions : LogOptions

[Description("Set the order of post processors in plugins")]
[CommandOption("--postProcessors")]
[TypeConverter(typeof(ArrayOptionConverter))]
public IEnumerable<string> 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.")]
Expand Down
1 change: 1 addition & 0 deletions src/docfx/Models/PdfCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal class PdfCommandOptions : BuildCommandOptions

[Description("Specify the toc files to be excluded")]
[CommandOption("--excludedTocs")]
[TypeConverter(typeof(ArrayOptionConverter))]
public IEnumerable<string> ExcludedTocs { get; set; }

[Description("Specify the base path to generate external link, {host}/{locale}/{basePath}")]
Expand Down

0 comments on commit f2f31fc

Please sign in to comment.