diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 48c2486..362325d 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -108,30 +108,31 @@ namespace AssetStudioCLI.Options 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)) { return; } - var optionDict = new Dictionary() { { name, desc } }; - if (!optionGroups.ContainsKey(group)) + var optionDesc = desc + example.Color(ColorConsole.BrightBlack); + var optionDict = new Dictionary() { { name, optionDesc } }; + if (optionGroups.TryGetValue(helpGroup, out Dictionary groupDict)) { - optionGroups.Add(group, optionDict); + groupDict.Add(name, optionDesc); } else { - optionGroups[group].Add(name, desc); + optionGroups.Add(helpGroup, optionDict); } if (isFlag) { - flagsDict.Add(name, desc); + flagsDict.Add(name, optionDesc); } else { - optionsDict.Add(name, desc); + optionsDict.Add(name, optionDesc); } } @@ -172,8 +173,8 @@ namespace AssetStudioCLI.Options "Dump - Makes asset dumps\n" + "Info - Loads file(s), shows the number of available for export assets and exits\n" + "Live2D - Exports Live2D Cubism 3 models\n" + - "SplitObjects - Exports split objects (fbx)\n" + - "Example: \"-m info\"\n", + "SplitObjects - Exports split objects (fbx)\n", + optionExample: "Example: \"-m info\"\n", optionHelpGroup: HelpGroups.General ); o_exportAssetTypes = new GroupedOption> @@ -184,8 +185,8 @@ namespace AssetStudioCLI.Options "\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" + - "Examples: \"-t sprite\" or \"-t tex2d,sprite,audio\" or \"-t tex2d;sprite;font\"\n", + "*To specify multiple asset types, write them separated by ',' or ';' without spaces\n", + optionExample: "Examples: \"-t sprite\" or \"-t tex2d,sprite,audio\" or \"-t tex2d;sprite;font\"\n", optionHelpGroup: HelpGroups.General ); o_groupAssetsBy = new GroupedOption @@ -198,8 +199,8 @@ namespace AssetStudioCLI.Options "Type - Group exported assets by type name\n" + "Container - Group exported assets by container path\n" + "ContainerFull - Group exported assets by full container path (e.g. with prefab name)\n" + - "Filename - Group exported assets by source file name\n" + - "Example: \"-g container\"\n", + "Filename - Group exported assets by source file name\n", + optionExample: "Example: \"-g container\"\n", optionHelpGroup: HelpGroups.General ); o_outputFolder = new GroupedOption @@ -208,6 +209,7 @@ namespace AssetStudioCLI.Options optionName: "-o, --output ", 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", + optionExample: "", optionHelpGroup: HelpGroups.General ); o_displayHelp = new GroupedOption @@ -215,6 +217,7 @@ namespace AssetStudioCLI.Options optionDefaultValue: false, optionName: "-h, --help", optionDescription: "Display help and exit", + optionExample: "", optionHelpGroup: HelpGroups.General ); #endregion @@ -225,8 +228,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: LoggerEvent.Info, optionName: "--log-level ", optionDescription: "Specify the log level\n" + - "\n" + - "Example: \"--log-level warning\"\n", + "\n", + optionExample: "Example: \"--log-level warning\"\n", optionHelpGroup: HelpGroups.Logger ); o_logOutput = new GroupedOption @@ -234,8 +237,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: LogOutputMode.Console, optionName: "--log-output ", optionDescription: "Specify the log output\n" + - "\n" + - "Example: \"--log-output both\"", + "\n", + optionExample: "Example: \"--log-output both\"", optionHelpGroup: HelpGroups.Logger ); #endregion @@ -248,8 +251,8 @@ namespace AssetStudioCLI.Options optionName: "--image-format ", optionDescription: "Specify the format for converting image assets\n" + "\n" + - "None - Do not convert images and export them as texture data (.tex)\n" + - "Example: \"--image-format jpg\"\n", + "None - Do not convert images and export them as texture data (.tex)\n", + optionExample: "Example: \"--image-format jpg\"\n", optionHelpGroup: HelpGroups.Convert ); o_audioFormat = new GroupedOption @@ -258,8 +261,8 @@ namespace AssetStudioCLI.Options optionName: "--audio-format ", optionDescription: "Specify the format for converting audio assets\n" + "\n" + - "None - Do not convert audios and export them in their own format\n" + - "Example: \"--audio-format wav\"", + "None - Do not convert audios and export them in their own format\n", + optionExample: "Example: \"--audio-format wav\"", optionHelpGroup: HelpGroups.Convert ); #endregion @@ -273,8 +276,8 @@ namespace AssetStudioCLI.Options "\n" + "MonoBehaviour - Try to export motions from MonoBehaviour Fade motions\n" + "If no Fade motions are found, the AnimationClip method will be used\n" + - "AnimationClip - Try to export motions using AnimationClip assets\n" + - "Example: \"--l2d-motion-mode animationClip\"\n", + "AnimationClip - Try to export motions using AnimationClip assets\n", + optionExample: "Example: \"--l2d-motion-mode animationClip\"\n", optionHelpGroup: HelpGroups.Live2D ); f_l2dForceBezier = new GroupedOption @@ -283,6 +286,7 @@ namespace AssetStudioCLI.Options optionName: "--l2d-force-bezier", 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)", + optionExample: "", optionHelpGroup: HelpGroups.Live2D, isFlag: true ); @@ -294,8 +298,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: 1f, optionName: "--fbx-scale-factor ", optionDescription: "Specify the FBX Scale Factor\n" + - " @@ -303,8 +307,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: 10, optionName: "--fbx-bone-size ", optionDescription: "Specify the FBX Bone Size\n" + - "(), optionName: "--filter-by-name ", optionDescription: "Specify the name by which assets should be filtered\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", + "*To specify multiple names write them separated by ',' or ';' without spaces\n", + optionExample: "Example: \"--filter-by-name char\" or \"--filter-by-name char,bg\"\n", optionHelpGroup: HelpGroups.Filter ); o_filterByContainer = new GroupedOption> @@ -324,8 +328,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: new List(), optionName: "--filter-by-container ", optionDescription: "Specify the container by which assets should be filtered\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", + "*To specify multiple containers write them separated by ',' or ';' without spaces\n", + optionExample: "Example: \"--filter-by-container arts\" or \"--filter-by-container arts,icons\"\n", optionHelpGroup: HelpGroups.Filter ); o_filterByPathID = new GroupedOption> @@ -333,8 +337,8 @@ namespace AssetStudioCLI.Options optionDefaultValue: new List(), optionName: "--filter-by-pathid ", optionDescription: "Specify the PathID by which assets should be filtered\n" + - "*To specify multiple PathIDs write them separated by ',' or ';' without spaces\n" + - "Example: \"--filter-by-pathid 7238605633795851352,-2430306240205277265\"\n", + "*To specify multiple PathIDs write them separated by ',' or ';' without spaces\n", + optionExample: "Example: \"--filter-by-pathid 7238605633795851352,-2430306240205277265\"\n", optionHelpGroup: HelpGroups.Filter ); o_filterByText = new GroupedOption> @@ -343,8 +347,8 @@ namespace AssetStudioCLI.Options optionName: "--filter-by-text ", 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" + - "*To specify multiple values write them separated by ',' or ';' without spaces\n" + - "Example: \"--filter-by-text portrait\" or \"--filter-by-text portrait,art\"\n", + "*To specify multiple values write them separated by ',' or ';' without spaces\n", + optionExample: "Example: \"--filter-by-text portrait\" or \"--filter-by-text portrait,art\"\n", optionHelpGroup: HelpGroups.Filter ); #endregion @@ -356,8 +360,8 @@ namespace AssetStudioCLI.Options optionName: "--export-asset-list ", optionDescription: "Specify the format in which you want to export asset list\n" + "\n" + - "None - Do not export asset list\n" + - "Example: \"--export-asset-list xml\"\n", + "None - Do not export asset list\n", + optionExample: "Example: \"--export-asset-list xml\"\n", optionHelpGroup: HelpGroups.Advanced ); o_assemblyPath = new GroupedOption @@ -365,13 +369,15 @@ namespace AssetStudioCLI.Options optionDefaultValue: "", optionName: "--assembly-folder ", optionDescription: "Specify the path to the assembly folder\n", + optionExample: "", optionHelpGroup: HelpGroups.Advanced ); o_unityVersion = new GroupedOption ( optionDefaultValue: "", optionName: "--unity-version ", - 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 ); f_notRestoreExtensionName = new GroupedOption @@ -379,6 +385,7 @@ namespace AssetStudioCLI.Options optionDefaultValue: false, 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", + optionExample: "", optionHelpGroup: HelpGroups.Advanced, isFlag: true ); @@ -387,6 +394,7 @@ namespace AssetStudioCLI.Options optionDefaultValue: false, optionName: "--load-all", optionDescription: "(Flag) If specified, AssetStudio will load assets of all types\n(Only for Dump, Info and ExportRaw modes)", + optionExample: "", optionHelpGroup: HelpGroups.Advanced, isFlag: true ); @@ -900,7 +908,7 @@ namespace AssetStudioCLI.Options private static bool TryFindOptionDescription(string option, Dictionary dict, bool isFlag = false) { var optionDesc = dict.Where(x => x.Key.Contains(option)).ToArray(); - if (optionDesc.Any()) + if (optionDesc.Length != 0) { var arg = isFlag ? "flag" : "option"; var rand = new Random(); @@ -919,12 +927,12 @@ namespace AssetStudioCLI.Options var helpMessage = new StringBuilder(); var usage = new StringBuilder(); var appAssembly = typeof(Program).Assembly.GetName(); - usage.Append($"Usage: {appAssembly.Name} "); + usage.Append($"{"Usage:".Color(ColorConsole.BrightYellow)} {appAssembly.Name} "); var i = 0; foreach (var optionsGroup in optionGroups.Keys) { - helpMessage.AppendLine($"{optionsGroup} Options:"); + helpMessage.AppendLine($"{optionsGroup} Options:".Color(ColorConsole.BrightYellow)); foreach (var optionDict in optionGroups[optionsGroup]) { var optionName = $"{optionDict.Key,-indent - 8}"; diff --git a/AssetStudioCLI/Options/Option.cs b/AssetStudioCLI/Options/Option.cs index 2626276..bf61e74 100644 --- a/AssetStudioCLI/Options/Option.cs +++ b/AssetStudioCLI/Options/Option.cs @@ -4,15 +4,17 @@ { public string Name { get; } public string Description { get; } + public string Example { get; } public T Value { get; set; } public T DefaultValue { get; } public HelpGroups HelpGroup { 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; Description = optionDescription; + Example = optionExample; DefaultValue = optionDefaultValue; Value = DefaultValue; HelpGroup = optionHelpGroup; diff --git a/AssetStudioCLI/Options/OptionExtensions.cs b/AssetStudioCLI/Options/OptionExtensions.cs index 1101e2e..bcbcf5d 100644 --- a/AssetStudioCLI/Options/OptionExtensions.cs +++ b/AssetStudioCLI/Options/OptionExtensions.cs @@ -4,14 +4,14 @@ namespace AssetStudioCLI.Options { internal static class OptionExtensions { - public static Action OptionGrouping = (name, desc, group, isFlag) => { }; + public static Action OptionGrouping = (name, desc, example, group, isFlag) => { }; } internal class GroupedOption : Option { - 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); } } }