Skip to content

Commit

Permalink
Update CommandLineParser library to the latest.
Browse files Browse the repository at this point in the history
Migrate parser usage to the 2.x API.
  • Loading branch information
Gwindalmir committed Sep 4, 2021
1 parent 3897b14 commit 87a2798
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 49 deletions.
2 changes: 1 addition & 1 deletion MEWorkshopTool/MEWorkshopTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser">
<Version>1.9.71</Version>
<Version>2.8.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion SEWorkshopTool/SEWorkshopTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser">
<Version>1.9.71</Version>
<Version>2.8.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
26 changes: 15 additions & 11 deletions WorkshopToolCommon/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using VRage.GameServices;
using System.Diagnostics;
using VRage;
using CommandLine;
#if SE
using ParallelTasks;
#else
Expand Down Expand Up @@ -128,7 +129,9 @@ public virtual int InitGame(string[] args)
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

if (parser.ParseArgumentsStrict(args, options, HandleInputError))
var result = parser.ParseArguments<Options>(args).WithNotParsed(l => HandleInputError());

if (result.Tag == ParserResultType.Parsed)
{
if (options.ModPaths == null &&
options.Blueprints == null &&
Expand All @@ -141,18 +144,18 @@ public virtual int InitGame(string[] args)
{
if (!options.ClearSteamCloud && !options.ListDLCs)
{
Console.WriteLine(CommandLine.Text.HelpText.AutoBuild(options).ToString());
Console.WriteLine(CommandLine.Text.HelpText.AutoBuild<Options>(result, null, null).ToString());
return Cleanup(1);
}
}

// If a "0" or "none" was specified for DLC, that means remove them all.
if(options.DLCs?.Length > 0 &&
if(options.DLCs?.Count() > 0 &&
(options.DLCs.Contains("0") || options.DLCs.Contains("none", StringComparer.InvariantCultureIgnoreCase)))
options.DLCs = new string[0];

// If a 0 was specified for dependencies, that means remove them all.
if (options.Dependencies?.Length > 0 && options.Dependencies.Contains((ulong)0))
if (options.Dependencies?.Count() > 0 && options.Dependencies.Contains((ulong)0))
options.Dependencies = new ulong[0];

// SE requires -appdata, but the commandline dll requires --appdata, so fix it
Expand Down Expand Up @@ -226,7 +229,7 @@ public virtual int InitGame(string[] args)
if (options.Download)
Task = DownloadMods(options);
else if (options.ClearSteamCloud)
Task = ClearSteamCloud(options.DeleteSteamCloudFiles, options.Force);
Task = ClearSteamCloud(options.DeleteSteamCloudFiles.ToArray(), options.Force);
else if (options.ListDLCs)
Task = System.Threading.Tasks.Task<bool>.Factory.StartNew(()=> { ListDLCs(); return true; });
else
Expand Down Expand Up @@ -532,7 +535,7 @@ static bool ProcessItemsUpload(WorkshopType type, List<string> paths, Options op
pathname = paths[idx];
}

var tags = options.Tags;
var tags = options.Tags.ToArray();

// If user comma-separated the tags, split them
if(tags != null && tags.Length == 1)
Expand Down Expand Up @@ -585,7 +588,7 @@ static bool ProcessItemsUpload(WorkshopType type, List<string> paths, Options op
}
}

var mod = new Uploader(type, pathname, tags, options.ExcludeExtensions, options.IgnorePaths, options.Compile, options.DryRun, options.Development, options.Visibility, options.Force, options.Thumbnail, options.DLCs, options.Dependencies, description, changelog);
var mod = new Uploader(type, pathname, tags, options.ExcludeExtensions.ToArray(), options.IgnorePaths.ToArray(), options.Compile, options.DryRun, options.Development, options.Visibility, options.Force, options.Thumbnail, options.DLCs.ToArray(), options.Dependencies.ToArray(), description, changelog);
if (options.UpdateOnly && ((IMod)mod).ModId == 0)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("--update-only passed, skipping: {0}", mod.Title));
Expand Down Expand Up @@ -692,7 +695,7 @@ static System.Threading.Tasks.Task<bool> DownloadMods(Options options)
return Task;
}

static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options options)
static bool ProcessItemsDownload(WorkshopType type, IEnumerable<string> paths, Options options)
{
if (paths == null)
return true;
Expand Down Expand Up @@ -850,8 +853,9 @@ static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options opti
#endregion Download

#region Pathing
static string[] TestPathAndMakeAbsolute(WorkshopType type, string[] paths)
static string[] TestPathAndMakeAbsolute(WorkshopType type, IEnumerable<string> pathsin)
{
var paths = pathsin.ToArray();
for (int idx = 0; paths != null && idx < paths.Length; idx++)
{
// If the passed in path doesn't exist, and is relative, try to match it with the expected data directory
Expand Down Expand Up @@ -918,7 +922,7 @@ private void ListDLCs()
#endif
}

static string[] CombineCollectionWithList(WorkshopType type, List<MyWorkshopItem> items, string[] existingitems)
static string[] CombineCollectionWithList(WorkshopType type, List<MyWorkshopItem> items, IEnumerable<string> existingitems)
{
var tempList = new List<string>();

Expand All @@ -935,7 +939,7 @@ static string[] CombineCollectionWithList(WorkshopType type, List<MyWorkshopItem

return tempList.ToArray();
}
return existingitems;
return existingitems.ToArray();
}

public static void CopyAll(string source, string target)
Expand Down
73 changes: 37 additions & 36 deletions WorkshopToolCommon/Options.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommandLine;
using System.Collections.Generic;
using VRage.GameServices;

namespace Phoenix.WorkshopTool
Expand All @@ -7,89 +8,89 @@ public sealed class Options
{
private const string OptionSet = "MainFunctions";

[Option("visibility", DefaultValue = null, HelpText = "Sets mod visibility (for new only). Accepted values: Public, FriendsOnly, Private, Unlisted")]
[Option("visibility", Default = null, HelpText = "Sets mod visibility (for new only). Accepted values: Public, FriendsOnly, Private, Unlisted")]
public PublishedFileVisibility? Visibility { get; set; }

[Option("dev", DefaultValue = false, HelpText = "Set to true if the mod will have the 'development' tag when uploaded (deprecated)")]
[Option("dev", Default = false, HelpText = "Set to true if the mod will have the 'development' tag when uploaded (deprecated)")]
public bool Development { get; set; }

[Option('c', "compile", DefaultValue = false, HelpText = "Compile the mod before uploading. Will not upload if compilation fails.")]
[Option('c', "compile", Default = false, HelpText = "Compile the mod before uploading. Will not upload if compilation fails.")]
public bool Compile { get; set; }

[Option('d', "dry-run", DefaultValue = false, HelpText = "Only run a test, do not actually upload. Useful with --compile")]
[Option('d', "dry-run", Default = false, HelpText = "Only run a test, do not actually upload. Useful with --compile")]
public bool DryRun { get; set; }

[Option("download", DefaultValue = false, HelpText = "Download mods", MutuallyExclusiveSet = OptionSet)]
[Option("download", Default = false, HelpText = "Download mods", SetName = "download")]
public bool Download { get; set; }

[Option("upload", DefaultValue = false, HelpText = "Upload and publish mods", MutuallyExclusiveSet = OptionSet)]
[Option("upload", Default = false, HelpText = "Upload and publish mods", SetName = "upload")]
public bool Upload { get; set; }

[Option('e', "extract", DefaultValue = false, HelpText = "Extract downloaded mods (valid for download only)")]
[Option('e', "extract", Default = false, HelpText = "Extract downloaded mods (valid for download only)")]
public bool Extract { get; set; }

[Option('u', "update-only", DefaultValue = false, HelpText = "Only update existing mods (don't upload new)")]
[Option('u', "update-only", Default = false, HelpText = "Only update existing mods (don't upload new)")]
public bool UpdateOnly { get; set; }

[OptionArray('x', "exclude", HelpText = "List of extensions to exclude from upload")]
public string[] ExcludeExtensions { get; set; }
[Option('x', "exclude", HelpText = "List of extensions to exclude from upload")]
public IEnumerable<string> ExcludeExtensions { get; set; }

[OptionArray("ignore", HelpText = "List of paths to exclude from upload")]
public string[] IgnorePaths { get; set; }
[Option("ignore", HelpText = "List of paths to exclude from upload")]
public IEnumerable<string> IgnorePaths { get; set; }

[Option('f', "force", DefaultValue = false, HelpText = "Force operation. USE WITH CAUTION! (not valid everywhere)")]
[Option('f', "force", Default = false, HelpText = "Force operation. USE WITH CAUTION! (not valid everywhere)")]
public bool Force { get; set; }

[OptionArray('m', "mods", HelpText = "List of directories of mods to upload; or Workshop ID of mods to download (when in download mode), use quotes if spaces")]
public string[] ModPaths { get; set; }
[Option('m', "mods", HelpText = "List of directories of mods to upload; or Workshop ID of mods to download (when in download mode), use quotes if spaces")]
public IEnumerable<string> ModPaths { get; set; }

[OptionArray('b', "blueprints", HelpText = "List of directories of blueprints to upload; or Workshop ID of blueprints to download (when in download mode)")]
public string[] Blueprints { get; set; }
[Option('b', "blueprints", HelpText = "List of directories of blueprints to upload; or Workshop ID of blueprints to download (when in download mode)")]
public IEnumerable<string> Blueprints { get; set; }

[OptionArray('s', "scenarios", HelpText = "List of directories of scenarios to upload; or Workshop ID of scenarios to download (when in download mode)")]
public string[] Scenarios { get; set; }
[Option('s', "scenarios", HelpText = "List of directories of scenarios to upload; or Workshop ID of scenarios to download (when in download mode)")]
public IEnumerable<string> Scenarios { get; set; }

[OptionArray('w', "worlds", HelpText = "List of directories of worlds to upload; or Workshop ID of worlds to download (when in download mode)")]
public string[] Worlds { get; set; }
[Option('w', "worlds", HelpText = "List of directories of worlds to upload; or Workshop ID of worlds to download (when in download mode)")]
public IEnumerable<string> Worlds { get; set; }

#if SE
[OptionArray('i', "scripts", HelpText = "List of directories of scripts to upload; or Workshop ID of scripts to download (when in download mode)")]
public string[] IngameScripts { get; set; }
[Option('i', "scripts", HelpText = "List of directories of scripts to upload; or Workshop ID of scripts to download (when in download mode)")]
public IEnumerable<string> IngameScripts { get; set; }
#endif
[OptionArray('t', "tags", HelpText = "List of workshop mod categories/tags to use (removes previous, default is keep existing)")]
public string[] Tags { get; set; }
[Option('t', "tags", HelpText = "List of workshop mod categories/tags to use (removes previous, default is keep existing)")]
public IEnumerable<string> Tags { get; set; }

[OptionArray("collections", HelpText = "List of Workshop IDs of collections to download")]
public string[] Collections { get; set; }
[Option("collections", HelpText = "List of Workshop IDs of collections to download")]
public IEnumerable<string> Collections { get; set; }

[Option("thumb", HelpText = "Thumbnail to upload (doesn't re-upload mod)")]
public string Thumbnail { get; set; }

[Option("clearsteamcloud", DefaultValue = false, HelpText = "Clear Steam Cloud (WARNING!). THIS WILL DELETE YOUR STEAM CLOUD FOR SE! Use with --force to actually delete.", MutuallyExclusiveSet = OptionSet)]
[Option("clearsteamcloud", Default = false, HelpText = "Clear Steam Cloud (WARNING!). THIS WILL DELETE YOUR STEAM CLOUD FOR SE! Use with --force to actually delete.", SetName = "cloud")]
public bool ClearSteamCloud { get; set; }

[OptionArray("deletecloudfile", HelpText = "Delete individual file or files from the Steam Cloud")]
public string[] DeleteSteamCloudFiles { get; set; }
[Option("deletecloudfile", HelpText = "Delete individual file or files from the Steam Cloud")]
public IEnumerable<string> DeleteSteamCloudFiles { get; set; }

#if SE
[Option("listdlc", HelpText = "List available DLCs", MutuallyExclusiveSet = OptionSet)]
[Option("listdlc", HelpText = "List available DLCs", SetName = "dlc")]
#endif
public bool ListDLCs { get; set; }

#if SE
[OptionArray("dlc", HelpText = "Add DLC dependency to mod, accepts numeric ID or name. Use 0 or None to remove all DLC.")]
[Option("dlc", HelpText = "Add DLC dependency to mod, accepts numeric ID or name. Use 0 or None to remove all DLC.")]
#endif
public string[] DLCs { get; set; }
public IEnumerable<string> DLCs { get; set; }

#if SE
[Option("modio", HelpText = "Use mod.io by default.")]
#endif
public bool ModIO { get; set; } = false;

[OptionArray("dependencies", HelpText = "Specify dependencies to other mods (modids only). Use 0 to remove all.")]
public ulong[] Dependencies { get; set; }
[Option("dependencies", HelpText = "Specify dependencies to other mods (modids only). Use 0 to remove all.")]
public IEnumerable<ulong> Dependencies { get; set; }

[Option("appdata", DefaultValue = "%AppData%\\SpaceEngineers", HelpText = "Specify custom AppData location")]
[Option("appdata", Default = "%AppData%\\SpaceEngineers", HelpText = "Specify custom AppData location")]
public string AppData { get; set; }

[Option("description", HelpText = "File containing the description to set for workshop item")]
Expand Down

0 comments on commit 87a2798

Please sign in to comment.