From 77f773248367133699cae5d130c9b18b9342357b Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Mon, 11 Oct 2021 20:13:00 +0000 Subject: [PATCH] Options for ckan show to hide sections --- Cmdline/Action/Show.cs | 165 ++++++++++++++++++++++------------------- Cmdline/Options.cs | 17 ++++- 2 files changed, 103 insertions(+), 79 deletions(-) diff --git a/Cmdline/Action/Show.cs b/Cmdline/Action/Show.cs index 98c2909ec3..7bd6e4cce0 100644 --- a/Cmdline/Action/Show.cs +++ b/Cmdline/Action/Show.cs @@ -35,7 +35,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options) // Show the installed module. combined_exit_code = CombineExitCodes( combined_exit_code, - ShowMod(installedModuleToShow) + ShowMod(installedModuleToShow, options) ); if (options.with_versions) { @@ -105,7 +105,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options) combined_exit_code = CombineExitCodes( combined_exit_code, - ShowMod(moduleToShow) + ShowMod(moduleToShow, options) ); if (options.with_versions) { @@ -121,12 +121,12 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options) /// /// Success status. /// The module to show. - public int ShowMod(InstalledModule module) + private int ShowMod(InstalledModule module, ShowOptions opts) { // Display the basic info. - int return_value = ShowMod(module.Module); + int return_value = ShowMod(module.Module, opts); - if (!module.Module.IsDLC) + if (!opts.without_files && !module.Module.IsDLC) { // Display InstalledModule specific information. ICollection files = module.Files as ICollection; @@ -151,100 +151,109 @@ public int ShowMod(InstalledModule module) /// /// Success status. /// The module to show. - public int ShowMod(CkanModule module) + private int ShowMod(CkanModule module, ShowOptions opts) { - #region Abstract and description - if (!string.IsNullOrEmpty(module.@abstract)) + if (!opts.without_description) { - user.RaiseMessage("{0}: {1}", module.name, module.@abstract); - } - else - { - user.RaiseMessage("{0}", module.name); + #region Abstract and description + if (!string.IsNullOrEmpty(module.@abstract)) + { + user.RaiseMessage("{0}: {1}", module.name, module.@abstract); + } + else + { + user.RaiseMessage("{0}", module.name); + } + + if (!string.IsNullOrEmpty(module.description)) + { + user.RaiseMessage(""); + user.RaiseMessage("{0}", module.description); + } + #endregion } - if (!string.IsNullOrEmpty(module.description)) + if (!opts.without_module_info) { + #region General info (author, version...) user.RaiseMessage(""); - user.RaiseMessage("{0}", module.description); - } - #endregion - - #region General info (author, version...) - user.RaiseMessage(""); - user.RaiseMessage("Module info:"); - user.RaiseMessage(" Version:\t{0}", module.version); - - if (module.author != null) - { - user.RaiseMessage(" Authors:\t{0}", string.Join(", ", module.author)); - } - else - { - // Did you know that authors are optional in the spec? - // You do now. #673. - user.RaiseMessage(" Authors:\tUNKNOWN"); - } - - if (module.release_status != null) - { - user.RaiseMessage(" Status:\t{0}", module.release_status); - } - user.RaiseMessage(" License:\t{0}", string.Join(", ", module.license)); - if (module.Tags != null && module.Tags.Count > 0) - { - // Need an extra space before the tab to line up with other fields - user.RaiseMessage(" Tags: \t{0}", string.Join(", ", module.Tags)); - } - if (module.localizations != null && module.localizations.Length > 0) - { - user.RaiseMessage(" Languages:\t{0}", string.Join(", ", module.localizations.OrderBy(l => l))); + user.RaiseMessage("Module info:"); + user.RaiseMessage(" Version:\t{0}", module.version); + + if (module.author != null) + { + user.RaiseMessage(" Authors:\t{0}", string.Join(", ", module.author)); + } + else + { + // Did you know that authors are optional in the spec? + // You do now. #673. + user.RaiseMessage(" Authors:\tUNKNOWN"); + } + + if (module.release_status != null) + { + user.RaiseMessage(" Status:\t{0}", module.release_status); + } + user.RaiseMessage(" License:\t{0}", string.Join(", ", module.license)); + if (module.Tags != null && module.Tags.Count > 0) + { + // Need an extra space before the tab to line up with other fields + user.RaiseMessage(" Tags: \t{0}", string.Join(", ", module.Tags)); + } + if (module.localizations != null && module.localizations.Length > 0) + { + user.RaiseMessage(" Languages:\t{0}", string.Join(", ", module.localizations.OrderBy(l => l))); + } + #endregion } - #endregion - #region Relationships - if (module.depends != null && module.depends.Count > 0) + if (!opts.without_relationships) { - user.RaiseMessage(""); - user.RaiseMessage("Depends:"); - foreach (RelationshipDescriptor dep in module.depends) + #region Relationships + if (module.depends != null && module.depends.Count > 0) { - user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + user.RaiseMessage(""); + user.RaiseMessage("Depends:"); + foreach (RelationshipDescriptor dep in module.depends) + { + user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + } } - } - if (module.recommends != null && module.recommends.Count > 0) - { - user.RaiseMessage(""); - user.RaiseMessage("Recommends:"); - foreach (RelationshipDescriptor dep in module.recommends) + if (module.recommends != null && module.recommends.Count > 0) { - user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + user.RaiseMessage(""); + user.RaiseMessage("Recommends:"); + foreach (RelationshipDescriptor dep in module.recommends) + { + user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + } } - } - if (module.suggests != null && module.suggests.Count > 0) - { - user.RaiseMessage(""); - user.RaiseMessage("Suggests:"); - foreach (RelationshipDescriptor dep in module.suggests) + if (module.suggests != null && module.suggests.Count > 0) { - user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + user.RaiseMessage(""); + user.RaiseMessage("Suggests:"); + foreach (RelationshipDescriptor dep in module.suggests) + { + user.RaiseMessage(" - {0}", RelationshipToPrintableString(dep)); + } } - } - if (module.provides != null && module.provides.Count > 0) - { - user.RaiseMessage(""); - user.RaiseMessage("Provides:"); - foreach (string prov in module.provides) + if (module.provides != null && module.provides.Count > 0) { - user.RaiseMessage(" - {0}", prov); + user.RaiseMessage(""); + user.RaiseMessage("Provides:"); + foreach (string prov in module.provides) + { + user.RaiseMessage(" - {0}", prov); + } } + #endregion } - #endregion - if (module.resources != null) + if (!opts.without_resources && module.resources != null) { user.RaiseMessage(""); user.RaiseMessage("Resources:"); @@ -286,7 +295,7 @@ public int ShowMod(CkanModule module) } } - if (!module.IsDLC) + if (!opts.without_files && !module.IsDLC) { // Compute the CKAN filename. string file_uri_hash = NetFileCache.CreateURLHash(module.download); diff --git a/Cmdline/Options.cs b/Cmdline/Options.cs index 1ce6a70238..50f5154d4d 100644 --- a/Cmdline/Options.cs +++ b/Cmdline/Options.cs @@ -516,7 +516,22 @@ internal class ImportOptions : InstanceSpecificOptions internal class ShowOptions : InstanceSpecificOptions { - [Option("with-versions")] + [Option("without-description", HelpText = "Don't show the name, abstract, or description")] + public bool without_description { get; set; } + + [Option("without-module-info", HelpText = "Don't show the version, authors, status, license, tags, languages")] + public bool without_module_info { get; set; } + + [Option("without-relationships", HelpText = "Don't show dependencies or conflicts")] + public bool without_relationships { get; set; } + + [Option("without-resources", HelpText = "Don't show home page, etc.")] + public bool without_resources { get; set; } + + [Option("without-files", HelpText = "Don't show contained files")] + public bool without_files { get; set; } + + [Option("with-versions", HelpText = "Print table of all versions of the mod and their compatible game versions")] public bool with_versions { get; set; } [ValueList(typeof(List))]