[CLI] Add colors to help message

This commit is contained in:
VaDiM 2024-02-08 22:35:48 +03:00
parent 70213e3012
commit 6fe12d274f
3 changed files with 55 additions and 45 deletions

View File

@ -108,30 +108,31 @@ namespace AssetStudioCLI.Options
InitOptions(); InitOptions();
} }
private static void OptionGrouping(string name, string desc, HelpGroups group, bool isFlag) private static void OptionGrouping(string name, string desc, string example, HelpGroups helpGroup, bool isFlag)
{ {
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
{ {
return; return;
} }
var optionDict = new Dictionary<string, string>() { { name, desc } }; var optionDesc = desc + example.Color(ColorConsole.BrightBlack);
if (!optionGroups.ContainsKey(group)) var optionDict = new Dictionary<string, string>() { { name, optionDesc } };
if (optionGroups.TryGetValue(helpGroup, out Dictionary<string, string> groupDict))
{ {
optionGroups.Add(group, optionDict); groupDict.Add(name, optionDesc);
} }
else else
{ {
optionGroups[group].Add(name, desc); optionGroups.Add(helpGroup, optionDict);
} }
if (isFlag) if (isFlag)
{ {
flagsDict.Add(name, desc); flagsDict.Add(name, optionDesc);
} }
else else
{ {
optionsDict.Add(name, desc); optionsDict.Add(name, optionDesc);
} }
} }
@ -172,8 +173,8 @@ namespace AssetStudioCLI.Options
"Dump - Makes asset dumps\n" + "Dump - Makes asset dumps\n" +
"Info - Loads file(s), shows the number of available for export assets and exits\n" + "Info - Loads file(s), shows the number of available for export assets and exits\n" +
"Live2D - Exports Live2D Cubism 3 models\n" + "Live2D - Exports Live2D Cubism 3 models\n" +
"SplitObjects - Exports split objects (fbx)\n" + "SplitObjects - Exports split objects (fbx)\n",
"Example: \"-m info\"\n", optionExample: "Example: \"-m info\"\n",
optionHelpGroup: HelpGroups.General optionHelpGroup: HelpGroups.General
); );
o_exportAssetTypes = new GroupedOption<List<ClassIDType>> o_exportAssetTypes = new GroupedOption<List<ClassIDType>>
@ -184,8 +185,8 @@ namespace AssetStudioCLI.Options
"<Value(s): tex2d, sprite, textAsset, monoBehaviour, font, shader, movieTexture,\n" + "<Value(s): tex2d, sprite, textAsset, monoBehaviour, font, shader, movieTexture,\n" +
"audio, video, mesh | all(default)>\n" + "audio, video, mesh | all(default)>\n" +
"All - export all asset types, which are listed in the values\n" + "All - export all asset types, which are listed in the values\n" +
"*To specify multiple asset types, write them separated by ',' or ';' without spaces\n" + "*To specify multiple asset types, write them separated by ',' or ';' without spaces\n",
"Examples: \"-t sprite\" or \"-t tex2d,sprite,audio\" or \"-t tex2d;sprite;font\"\n", optionExample: "Examples: \"-t sprite\" or \"-t tex2d,sprite,audio\" or \"-t tex2d;sprite;font\"\n",
optionHelpGroup: HelpGroups.General optionHelpGroup: HelpGroups.General
); );
o_groupAssetsBy = new GroupedOption<AssetGroupOption> o_groupAssetsBy = new GroupedOption<AssetGroupOption>
@ -198,8 +199,8 @@ namespace AssetStudioCLI.Options
"Type - Group exported assets by type name\n" + "Type - Group exported assets by type name\n" +
"Container - Group exported assets by container path\n" + "Container - Group exported assets by container path\n" +
"ContainerFull - Group exported assets by full container path (e.g. with prefab name)\n" + "ContainerFull - Group exported assets by full container path (e.g. with prefab name)\n" +
"Filename - Group exported assets by source file name\n" + "Filename - Group exported assets by source file name\n",
"Example: \"-g container\"\n", optionExample: "Example: \"-g container\"\n",
optionHelpGroup: HelpGroups.General optionHelpGroup: HelpGroups.General
); );
o_outputFolder = new GroupedOption<string> o_outputFolder = new GroupedOption<string>
@ -208,6 +209,7 @@ namespace AssetStudioCLI.Options
optionName: "-o, --output <path>", optionName: "-o, --output <path>",
optionDescription: "Specify path to the output folder\n" + optionDescription: "Specify path to the output folder\n" +
"If path isn't specified, 'ASExport' folder will be created in the program's work folder\n", "If path isn't specified, 'ASExport' folder will be created in the program's work folder\n",
optionExample: "",
optionHelpGroup: HelpGroups.General optionHelpGroup: HelpGroups.General
); );
o_displayHelp = new GroupedOption<bool> o_displayHelp = new GroupedOption<bool>
@ -215,6 +217,7 @@ namespace AssetStudioCLI.Options
optionDefaultValue: false, optionDefaultValue: false,
optionName: "-h, --help", optionName: "-h, --help",
optionDescription: "Display help and exit", optionDescription: "Display help and exit",
optionExample: "",
optionHelpGroup: HelpGroups.General optionHelpGroup: HelpGroups.General
); );
#endregion #endregion
@ -225,8 +228,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: LoggerEvent.Info, optionDefaultValue: LoggerEvent.Info,
optionName: "--log-level <value>", optionName: "--log-level <value>",
optionDescription: "Specify the log level\n" + optionDescription: "Specify the log level\n" +
"<Value: verbose | debug | info(default) | warning | error>\n" + "<Value: verbose | debug | info(default) | warning | error>\n",
"Example: \"--log-level warning\"\n", optionExample: "Example: \"--log-level warning\"\n",
optionHelpGroup: HelpGroups.Logger optionHelpGroup: HelpGroups.Logger
); );
o_logOutput = new GroupedOption<LogOutputMode> o_logOutput = new GroupedOption<LogOutputMode>
@ -234,8 +237,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: LogOutputMode.Console, optionDefaultValue: LogOutputMode.Console,
optionName: "--log-output <value>", optionName: "--log-output <value>",
optionDescription: "Specify the log output\n" + optionDescription: "Specify the log output\n" +
"<Value: console(default) | file | both>\n" + "<Value: console(default) | file | both>\n",
"Example: \"--log-output both\"", optionExample: "Example: \"--log-output both\"",
optionHelpGroup: HelpGroups.Logger optionHelpGroup: HelpGroups.Logger
); );
#endregion #endregion
@ -248,8 +251,8 @@ namespace AssetStudioCLI.Options
optionName: "--image-format <value>", optionName: "--image-format <value>",
optionDescription: "Specify the format for converting image assets\n" + optionDescription: "Specify the format for converting image assets\n" +
"<Value: none | jpg | png(default) | bmp | tga | webp>\n" + "<Value: none | jpg | png(default) | bmp | tga | webp>\n" +
"None - Do not convert images and export them as texture data (.tex)\n" + "None - Do not convert images and export them as texture data (.tex)\n",
"Example: \"--image-format jpg\"\n", optionExample: "Example: \"--image-format jpg\"\n",
optionHelpGroup: HelpGroups.Convert optionHelpGroup: HelpGroups.Convert
); );
o_audioFormat = new GroupedOption<AudioFormat> o_audioFormat = new GroupedOption<AudioFormat>
@ -258,8 +261,8 @@ namespace AssetStudioCLI.Options
optionName: "--audio-format <value>", optionName: "--audio-format <value>",
optionDescription: "Specify the format for converting audio assets\n" + optionDescription: "Specify the format for converting audio assets\n" +
"<Value: none | wav(default)>\n" + "<Value: none | wav(default)>\n" +
"None - Do not convert audios and export them in their own format\n" + "None - Do not convert audios and export them in their own format\n",
"Example: \"--audio-format wav\"", optionExample: "Example: \"--audio-format wav\"",
optionHelpGroup: HelpGroups.Convert optionHelpGroup: HelpGroups.Convert
); );
#endregion #endregion
@ -273,8 +276,8 @@ namespace AssetStudioCLI.Options
"<Value: monoBehaviour(default) | animationClip>\n" + "<Value: monoBehaviour(default) | animationClip>\n" +
"MonoBehaviour - Try to export motions from MonoBehaviour Fade motions\n" + "MonoBehaviour - Try to export motions from MonoBehaviour Fade motions\n" +
"If no Fade motions are found, the AnimationClip method will be used\n" + "If no Fade motions are found, the AnimationClip method will be used\n" +
"AnimationClip - Try to export motions using AnimationClip assets\n" + "AnimationClip - Try to export motions using AnimationClip assets\n",
"Example: \"--l2d-motion-mode animationClip\"\n", optionExample: "Example: \"--l2d-motion-mode animationClip\"\n",
optionHelpGroup: HelpGroups.Live2D optionHelpGroup: HelpGroups.Live2D
); );
f_l2dForceBezier = new GroupedOption<bool> f_l2dForceBezier = new GroupedOption<bool>
@ -283,6 +286,7 @@ namespace AssetStudioCLI.Options
optionName: "--l2d-force-bezier", optionName: "--l2d-force-bezier",
optionDescription: "(Flag) If specified, Linear motion segments will be calculated as Bezier segments\n" + optionDescription: "(Flag) If specified, Linear motion segments will be calculated as Bezier segments\n" +
"(May help if the exported motions look jerky/not smooth enough)", "(May help if the exported motions look jerky/not smooth enough)",
optionExample: "",
optionHelpGroup: HelpGroups.Live2D, optionHelpGroup: HelpGroups.Live2D,
isFlag: true isFlag: true
); );
@ -294,8 +298,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: 1f, optionDefaultValue: 1f,
optionName: "--fbx-scale-factor <value>", optionName: "--fbx-scale-factor <value>",
optionDescription: "Specify the FBX Scale Factor\n" + optionDescription: "Specify the FBX Scale Factor\n" +
"<Value: float number from 0 to 100 (default=1)\n" + "<Value: float number from 0 to 100 (default=1)\n",
"Example: \"--fbx-scale-factor 50\"\n", optionExample: "Example: \"--fbx-scale-factor 50\"\n",
optionHelpGroup: HelpGroups.FBX optionHelpGroup: HelpGroups.FBX
); );
o_fbxBoneSize = new GroupedOption<int> o_fbxBoneSize = new GroupedOption<int>
@ -303,8 +307,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: 10, optionDefaultValue: 10,
optionName: "--fbx-bone-size <value>", optionName: "--fbx-bone-size <value>",
optionDescription: "Specify the FBX Bone Size\n" + optionDescription: "Specify the FBX Bone Size\n" +
"<Value: integer number from 0 to 100 (default=10)\n" + "<Value: integer number from 0 to 100 (default=10)\n",
"Example: \"--fbx-bone-size 10\"", optionExample: "Example: \"--fbx-bone-size 10\"",
optionHelpGroup: HelpGroups.FBX optionHelpGroup: HelpGroups.FBX
); );
#endregion #endregion
@ -315,8 +319,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: new List<string>(), optionDefaultValue: new List<string>(),
optionName: "--filter-by-name <text>", optionName: "--filter-by-name <text>",
optionDescription: "Specify the name by which assets should be filtered\n" + optionDescription: "Specify the name by which assets should be filtered\n" +
"*To specify multiple names write them separated by ',' or ';' without spaces\n" + "*To specify multiple names write them separated by ',' or ';' without spaces\n",
"Example: \"--filter-by-name char\" or \"--filter-by-name char,bg\"\n", optionExample: "Example: \"--filter-by-name char\" or \"--filter-by-name char,bg\"\n",
optionHelpGroup: HelpGroups.Filter optionHelpGroup: HelpGroups.Filter
); );
o_filterByContainer = new GroupedOption<List<string>> o_filterByContainer = new GroupedOption<List<string>>
@ -324,8 +328,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: new List<string>(), optionDefaultValue: new List<string>(),
optionName: "--filter-by-container <text>", optionName: "--filter-by-container <text>",
optionDescription: "Specify the container by which assets should be filtered\n" + optionDescription: "Specify the container by which assets should be filtered\n" +
"*To specify multiple containers write them separated by ',' or ';' without spaces\n" + "*To specify multiple containers write them separated by ',' or ';' without spaces\n",
"Example: \"--filter-by-container arts\" or \"--filter-by-container arts,icons\"\n", optionExample: "Example: \"--filter-by-container arts\" or \"--filter-by-container arts,icons\"\n",
optionHelpGroup: HelpGroups.Filter optionHelpGroup: HelpGroups.Filter
); );
o_filterByPathID = new GroupedOption<List<string>> o_filterByPathID = new GroupedOption<List<string>>
@ -333,8 +337,8 @@ namespace AssetStudioCLI.Options
optionDefaultValue: new List<string>(), optionDefaultValue: new List<string>(),
optionName: "--filter-by-pathid <text>", optionName: "--filter-by-pathid <text>",
optionDescription: "Specify the PathID by which assets should be filtered\n" + optionDescription: "Specify the PathID by which assets should be filtered\n" +
"*To specify multiple PathIDs write them separated by ',' or ';' without spaces\n" + "*To specify multiple PathIDs write them separated by ',' or ';' without spaces\n",
"Example: \"--filter-by-pathid 7238605633795851352,-2430306240205277265\"\n", optionExample: "Example: \"--filter-by-pathid 7238605633795851352,-2430306240205277265\"\n",
optionHelpGroup: HelpGroups.Filter optionHelpGroup: HelpGroups.Filter
); );
o_filterByText = new GroupedOption<List<string>> o_filterByText = new GroupedOption<List<string>>
@ -343,8 +347,8 @@ namespace AssetStudioCLI.Options
optionName: "--filter-by-text <text>", optionName: "--filter-by-text <text>",
optionDescription: "Specify the text by which assets should be filtered\n" + optionDescription: "Specify the text by which assets should be filtered\n" +
"Looks for assets that contain the specified text in their names or containers\n" + "Looks for assets that contain the specified text in their names or containers\n" +
"*To specify multiple values write them separated by ',' or ';' without spaces\n" + "*To specify multiple values write them separated by ',' or ';' without spaces\n",
"Example: \"--filter-by-text portrait\" or \"--filter-by-text portrait,art\"\n", optionExample: "Example: \"--filter-by-text portrait\" or \"--filter-by-text portrait,art\"\n",
optionHelpGroup: HelpGroups.Filter optionHelpGroup: HelpGroups.Filter
); );
#endregion #endregion
@ -356,8 +360,8 @@ namespace AssetStudioCLI.Options
optionName: "--export-asset-list <value>", optionName: "--export-asset-list <value>",
optionDescription: "Specify the format in which you want to export asset list\n" + optionDescription: "Specify the format in which you want to export asset list\n" +
"<Value: none(default) | xml>\n" + "<Value: none(default) | xml>\n" +
"None - Do not export asset list\n" + "None - Do not export asset list\n",
"Example: \"--export-asset-list xml\"\n", optionExample: "Example: \"--export-asset-list xml\"\n",
optionHelpGroup: HelpGroups.Advanced optionHelpGroup: HelpGroups.Advanced
); );
o_assemblyPath = new GroupedOption<string> o_assemblyPath = new GroupedOption<string>
@ -365,13 +369,15 @@ namespace AssetStudioCLI.Options
optionDefaultValue: "", optionDefaultValue: "",
optionName: "--assembly-folder <path>", optionName: "--assembly-folder <path>",
optionDescription: "Specify the path to the assembly folder\n", optionDescription: "Specify the path to the assembly folder\n",
optionExample: "",
optionHelpGroup: HelpGroups.Advanced optionHelpGroup: HelpGroups.Advanced
); );
o_unityVersion = new GroupedOption<string> o_unityVersion = new GroupedOption<string>
( (
optionDefaultValue: "", optionDefaultValue: "",
optionName: "--unity-version <text>", optionName: "--unity-version <text>",
optionDescription: "Specify Unity version\nExample: \"--unity-version 2017.4.39f1\"\n", optionDescription: "Specify Unity version\n",
optionExample: "Example: \"--unity-version 2017.4.39f1\"\n",
optionHelpGroup: HelpGroups.Advanced optionHelpGroup: HelpGroups.Advanced
); );
f_notRestoreExtensionName = new GroupedOption<bool> f_notRestoreExtensionName = new GroupedOption<bool>
@ -379,6 +385,7 @@ namespace AssetStudioCLI.Options
optionDefaultValue: false, optionDefaultValue: false,
optionName: "--not-restore-extension", optionName: "--not-restore-extension",
optionDescription: "(Flag) If specified, AssetStudio will not try to use/restore original TextAsset\nextension name, and will just export all TextAssets with the \".txt\" extension\n", optionDescription: "(Flag) If specified, AssetStudio will not try to use/restore original TextAsset\nextension name, and will just export all TextAssets with the \".txt\" extension\n",
optionExample: "",
optionHelpGroup: HelpGroups.Advanced, optionHelpGroup: HelpGroups.Advanced,
isFlag: true isFlag: true
); );
@ -387,6 +394,7 @@ namespace AssetStudioCLI.Options
optionDefaultValue: false, optionDefaultValue: false,
optionName: "--load-all", optionName: "--load-all",
optionDescription: "(Flag) If specified, AssetStudio will load assets of all types\n(Only for Dump, Info and ExportRaw modes)", optionDescription: "(Flag) If specified, AssetStudio will load assets of all types\n(Only for Dump, Info and ExportRaw modes)",
optionExample: "",
optionHelpGroup: HelpGroups.Advanced, optionHelpGroup: HelpGroups.Advanced,
isFlag: true isFlag: true
); );
@ -900,7 +908,7 @@ namespace AssetStudioCLI.Options
private static bool TryFindOptionDescription(string option, Dictionary<string, string> dict, bool isFlag = false) private static bool TryFindOptionDescription(string option, Dictionary<string, string> dict, bool isFlag = false)
{ {
var optionDesc = dict.Where(x => x.Key.Contains(option)).ToArray(); var optionDesc = dict.Where(x => x.Key.Contains(option)).ToArray();
if (optionDesc.Any()) if (optionDesc.Length != 0)
{ {
var arg = isFlag ? "flag" : "option"; var arg = isFlag ? "flag" : "option";
var rand = new Random(); var rand = new Random();
@ -919,12 +927,12 @@ namespace AssetStudioCLI.Options
var helpMessage = new StringBuilder(); var helpMessage = new StringBuilder();
var usage = new StringBuilder(); var usage = new StringBuilder();
var appAssembly = typeof(Program).Assembly.GetName(); var appAssembly = typeof(Program).Assembly.GetName();
usage.Append($"Usage: {appAssembly.Name} <input path to asset file/folder> "); usage.Append($"{"Usage:".Color(ColorConsole.BrightYellow)} {appAssembly.Name} <input path to asset file/folder> ");
var i = 0; var i = 0;
foreach (var optionsGroup in optionGroups.Keys) foreach (var optionsGroup in optionGroups.Keys)
{ {
helpMessage.AppendLine($"{optionsGroup} Options:"); helpMessage.AppendLine($"{optionsGroup} Options:".Color(ColorConsole.BrightYellow));
foreach (var optionDict in optionGroups[optionsGroup]) foreach (var optionDict in optionGroups[optionsGroup])
{ {
var optionName = $"{optionDict.Key,-indent - 8}"; var optionName = $"{optionDict.Key,-indent - 8}";

View File

@ -4,15 +4,17 @@
{ {
public string Name { get; } public string Name { get; }
public string Description { get; } public string Description { get; }
public string Example { get; }
public T Value { get; set; } public T Value { get; set; }
public T DefaultValue { get; } public T DefaultValue { get; }
public HelpGroups HelpGroup { get; } public HelpGroups HelpGroup { get; }
public bool IsFlag { get; } public bool IsFlag { get; }
public Option(T optionDefaultValue, string optionName, string optionDescription, HelpGroups optionHelpGroup, bool isFlag) public Option(T optionDefaultValue, string optionName, string optionDescription, string optionExample, HelpGroups optionHelpGroup, bool isFlag)
{ {
Name = optionName; Name = optionName;
Description = optionDescription; Description = optionDescription;
Example = optionExample;
DefaultValue = optionDefaultValue; DefaultValue = optionDefaultValue;
Value = DefaultValue; Value = DefaultValue;
HelpGroup = optionHelpGroup; HelpGroup = optionHelpGroup;

View File

@ -4,14 +4,14 @@ namespace AssetStudioCLI.Options
{ {
internal static class OptionExtensions internal static class OptionExtensions
{ {
public static Action<string, string, HelpGroups, bool> OptionGrouping = (name, desc, group, isFlag) => { }; public static Action<string, string, string, HelpGroups, bool> OptionGrouping = (name, desc, example, group, isFlag) => { };
} }
internal class GroupedOption<T> : Option<T> internal class GroupedOption<T> : Option<T>
{ {
public GroupedOption(T optionDefaultValue, string optionName, string optionDescription, HelpGroups optionHelpGroup, bool isFlag = false) : base(optionDefaultValue, optionName, optionDescription, optionHelpGroup, isFlag) public GroupedOption(T optionDefaultValue, string optionName, string optionDescription, string optionExample, HelpGroups optionHelpGroup, bool isFlag = false) : base(optionDefaultValue, optionName, optionDescription, optionExample, optionHelpGroup, isFlag)
{ {
OptionExtensions.OptionGrouping(optionName, optionDescription, optionHelpGroup, isFlag); OptionExtensions.OptionGrouping(optionName, optionDescription, optionExample, optionHelpGroup, isFlag);
} }
} }
} }