Skip to content

Commit

Permalink
Merge #3461 Options for ckan show to hide sections
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 1, 2021
2 parents 8a3bd59 + 77f7732 commit 988a39e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Add user guide and Discord to GUI help menu (#3437 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Label ordering buttons (#3416 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Suppress incompatibility warning at game launch (#3453 by: HebaruSan; reviewed: DasSkelett)
- [CLI] Options for ckan show to hide sections (#3461 by: HebaruSan; reviewed: DasSkelett)

### Bugfixes

Expand Down
165 changes: 87 additions & 78 deletions Cmdline/Action/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -121,12 +121,12 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
/// </summary>
/// <returns>Success status.</returns>
/// <param name="module">The module to show.</param>
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<string> files = module.Files as ICollection<string>;
Expand All @@ -151,100 +151,109 @@ public int ShowMod(InstalledModule module)
/// </summary>
/// <returns>Success status.</returns>
/// <param name="module">The module to show.</param>
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:");
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion Cmdline/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>))]
Expand Down

0 comments on commit 988a39e

Please sign in to comment.