Skip to content

Commit

Permalink
feat: specify global metadata with -m|--metadata arg
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed Jun 2, 2023
1 parent 3e73134 commit b4964d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/docfx/Models/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,37 @@ internal static void MergeOptionsToConfig(BuildCommandOptions options, BuildJson
new ListWithStringFallback(config.GlobalMetadataFilePaths.Select(
path => PathUtility.IsRelativePath(path) ? Path.Combine(configDirectory, path) : path).Reverse());

SetGlobalMetadataFromCommandLineArgs();

config.KeepFileLink |= options.KeepFileLink;
config.DisableGitFeatures |= options.DisableGitFeatures;

void SetGlobalMetadataFromCommandLineArgs()
{
if (options.Metadata != null)
{
config.GlobalMetadata ??= new();
foreach (var metadata in options.Metadata)
{
var (key, value) = ParseMetadata(metadata);
config.GlobalMetadata[key] = value;
}
}

static (string key, object value) ParseMetadata(string metadata)
{
if (metadata.IndexOf('=') is int i && i < 0)
return (metadata, true);

var key = metadata.Substring(0, i);
var value = metadata.Substring(i + 1);

if (bool.TryParse(value, out var boolean))
return (key, boolean);

return (key, value);
}
}
}

private sealed class BuildConfig
Expand Down
4 changes: 4 additions & 0 deletions src/docfx/Models/BuildCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ internal class BuildCommandOptions : LogOptions
[CommandArgument(0, "[config]")]
public string ConfigFile { get; set; }

[Description("Specify a list of global metadata in key value pairs (e.g., --metadata _appTitle=\"My App\" --metadata _disableContribution)")]
[CommandOption("-m|--metadata")]
public string[] Metadata { get; set; }

[Description("Specify the urls of xrefmap used by content files.")]
[CommandOption("-x|--xref")]
[TypeConverter(typeof(ArrayOptionConverter))]
Expand Down

0 comments on commit b4964d9

Please sign in to comment.