Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ckan compat add take multiple versions, add clear and set #4151

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions Cmdline/Action/AuthToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,39 @@ internal class AuthTokenSubOptions : VerbCommandOptions
[HelpVerbOption]
public string GetUsage(string verb)
{
HelpText ht = HelpText.AutoBuild(this, verb);
var ht = HelpText.AutoBuild(this, verb);
foreach (var h in GetHelp(verb))
{
ht.AddPreOptionsLine(h);
}
return ht;
}

public static IEnumerable<string> GetHelp(string verb)
{
// Add a usage prefix line
ht.AddPreOptionsLine(" ");
yield return " ";
if (string.IsNullOrEmpty(verb))
{
ht.AddPreOptionsLine($"ckan authtoken - {Properties.Resources.AuthTokenHelpSummary}");
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan authtoken <{Properties.Resources.Command}> [{Properties.Resources.Options}]");
yield return $"ckan authtoken - {Properties.Resources.AuthTokenHelpSummary}";
yield return $"{Properties.Resources.Usage}: ckan authtoken <{Properties.Resources.Command}> [{Properties.Resources.Options}]";
}
else
{
ht.AddPreOptionsLine("authtoken " + verb + " - " + GetDescription(verb));
yield return "authtoken " + verb + " - " + GetDescription(typeof(AuthTokenSubOptions), verb);
switch (verb)
{
case "add":
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}] host token");
yield return $"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}] host token";
break;
case "remove":
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}] host");
yield return $"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}] host";
break;
case "list":
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}]");
yield return $"{Properties.Resources.Usage}: ckan authtoken {verb} [{Properties.Resources.Options}]";
break;
}
}
return ht;
}
}

Expand Down
9 changes: 9 additions & 0 deletions Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Linq;

using CommandLine;

namespace CKAN.CmdLine
{
public class Available : ICommand
Expand Down Expand Up @@ -45,4 +47,11 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
private readonly IUser user;
private readonly RepositoryDataManager repoData;
}

internal class AvailableOptions : InstanceSpecificOptions
{
[Option("detail", HelpText = "Show short description of each module")]
public bool detail { get; set; }
}

}
39 changes: 29 additions & 10 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

using CommandLine;
using CommandLine.Text;
using Autofac;
Expand Down Expand Up @@ -29,25 +31,34 @@ public class CacheSubOptions : VerbCommandOptions
[HelpVerbOption]
public string GetUsage(string verb)
{
HelpText ht = HelpText.AutoBuild(this, verb);
var ht = HelpText.AutoBuild(this, verb);
foreach (var h in GetHelp(verb))
{
ht.AddPreOptionsLine(h);
}
return ht;
}

public static IEnumerable<string> GetHelp(string verb)
{
// Add a usage prefix line
ht.AddPreOptionsLine(" ");
yield return " ";
if (string.IsNullOrEmpty(verb))
{
ht.AddPreOptionsLine($"ckan cache - {Properties.Resources.CacheHelpSummary}");
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan cache <{Properties.Resources.Command}> [{Properties.Resources.Options}]");
yield return $"ckan cache - {Properties.Resources.CacheHelpSummary}";
yield return $"{Properties.Resources.Usage}: ckan cache <{Properties.Resources.Command}> [{Properties.Resources.Options}]";
}
else
{
ht.AddPreOptionsLine("cache " + verb + " - " + GetDescription(verb));
yield return "cache " + verb + " - " + GetDescription(typeof(CacheSubOptions), verb);
switch (verb)
{
// First the commands with one string argument
case "set":
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}] path");
yield return $"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}] path";
break;
case "setlimit":
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}] megabytes");
yield return $"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}] megabytes";
break;

// Now the commands with only --flag type options
Expand All @@ -56,11 +67,10 @@ public string GetUsage(string verb)
case "reset":
case "showlimit":
default:
ht.AddPreOptionsLine($"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}]");
yield return $"{Properties.Resources.Usage}: ckan cache {verb} [{Properties.Resources.Options}]";
break;
}
}
return ht;
}
}

Expand Down Expand Up @@ -158,7 +168,8 @@ private int SetCacheDirectory(SetOptions options)
{
if (string.IsNullOrEmpty(options.Path))
{
user.RaiseError("set <{0}> - {1}", Properties.Resources.Path, Properties.Resources.ArgumentMissing);
user.RaiseError(Properties.Resources.ArgumentMissing);
PrintUsage("set");
return Exit.BADOPT;
}

Expand Down Expand Up @@ -231,6 +242,14 @@ private void printCacheInfo()
CkanModule.FmtSize(bytesFree));
}

private void PrintUsage(string verb)
{
foreach (var h in CacheSubOptions.GetHelp(verb))
{
user.RaiseError(h);
}
}

private IUser user;
private GameInstanceManager manager;
}
Expand Down
18 changes: 17 additions & 1 deletion Cmdline/Action/Compare.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using CommandLine;

using CKAN.Versioning;

namespace CKAN.CmdLine
Expand Down Expand Up @@ -46,11 +48,25 @@ public int RunCommand(object rawOptions)
}
else
{
user.RaiseMessage("{0}: ckan compare version1 version2", Properties.Resources.Usage);
user.RaiseError(Properties.Resources.ArgumentMissing);
foreach (var h in Actions.GetHelp("compare"))
{
user.RaiseError(h);
}
return Exit.BADOPT;
}

return Exit.OK;
}
}

internal class CompareOptions : CommonOptions
{
[Option("machine-readable", HelpText = "Output in a machine readable format: -1, 0 or 1")]
public bool machine_readable { get; set;}

[ValueOption(0)] public string Left { get; set; }
[ValueOption(1)] public string Right { get; set; }
}

}
Loading