Skip to content

Commit

Permalink
Make ckan compat add accept multiple version parameters, add `clear…
Browse files Browse the repository at this point in the history
…` and `set`
  • Loading branch information
HebaruSan committed Aug 8, 2024
1 parent 66b1502 commit cec6a07
Show file tree
Hide file tree
Showing 22 changed files with 751 additions and 472 deletions.
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

0 comments on commit cec6a07

Please sign in to comment.