Use Mono.Options as command line parser.

This commit is contained in:
2019-01-05 16:59:23 +00:00
parent bbedcfe843
commit 104bc55c5e
30 changed files with 2221 additions and 1392 deletions

View File

@@ -30,25 +30,67 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System.Collections.Generic;
using DiscImageChef.Console;
using DiscImageChef.Core;
using Mono.Options;
namespace DiscImageChef.Commands
{
static class Update
class UpdateCommand : Command
{
internal static void DoUpdate(UpdateOptions options)
readonly bool masterDbUpdate;
bool showHelp;
public UpdateCommand(bool masterDbUpdate) : base("update", "Updates the database.")
{
DicConsole.DebugWriteLine("Media-Info command", "--debug={0}", options.Debug);
DicConsole.DebugWriteLine("Media-Info command", "--verbose={0}", options.Verbose);
this.masterDbUpdate = masterDbUpdate;
Options = new OptionSet
{
$"{MainClass.AssemblyTitle} {MainClass.AssemblyVersion?.InformationalVersion}",
$"{MainClass.AssemblyCopyright}",
"",
$"usage: DiscImageChef {Name}",
"",
Help,
{"help|h|?", "Show this message and exit.", v => showHelp = v != null}
};
}
public override int Invoke(IEnumerable<string> arguments)
{
if(masterDbUpdate) return 0;
List<string> extra = Options.Parse(arguments);
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
}
MainClass.PrintCopyright();
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
}
DicConsole.DebugWriteLine("Update command", "--debug={0}", MainClass.Debug);
DicConsole.DebugWriteLine("Update command", "--verbose={0}", MainClass.Verbose);
DoUpdate(false);
return 0;
}
internal static void DoUpdate(bool create)
{
Remote.UpdateMasterDatabase(create);
Core.Statistics.AddCommand("update");
Statistics.AddCommand("update");
}
}
}