Port command line argument handling to Mono.Options
This commit is contained in:
parent
18c5040ce4
commit
65de283014
|
@ -5,6 +5,7 @@ LINK = $(REF_SPARKLELIB)
|
||||||
|
|
||||||
SOURCES = \
|
SOURCES = \
|
||||||
Defines.cs \
|
Defines.cs \
|
||||||
|
MonoOptions.cs \
|
||||||
SparkleFetcher.cs \
|
SparkleFetcher.cs \
|
||||||
SparkleHelpers.cs \
|
SparkleHelpers.cs \
|
||||||
SparklePaths.cs \
|
SparklePaths.cs \
|
||||||
|
|
1101
SparkleLib/MonoOptions.cs
Normal file
1101
SparkleLib/MonoOptions.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -17,9 +17,11 @@
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using Mono.Unix;
|
using Mono.Unix;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using SparkleLib;
|
using SparkleLib;
|
||||||
|
using Mono.Options;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
@ -75,32 +77,25 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
bool HideUI = false;
|
bool HideUI = false;
|
||||||
|
bool ShowHelp = false;
|
||||||
|
var p = new OptionSet () {
|
||||||
|
{ "d|disable-gui", _("Don't show the notification icon"), v => HideUI = v != null },
|
||||||
|
{ "v|version", _("Show this help text."), v => { PrintVersion (); Environment.Exit (0); } },
|
||||||
|
{ "h|help", _("Print version information."), v=> ShowHelp = v != null }
|
||||||
|
};
|
||||||
|
|
||||||
// Parse the command line arguments
|
List<string> extra;
|
||||||
if (args.Length > 0) {
|
try {
|
||||||
|
extra = p.Parse (args);
|
||||||
foreach (string Argument in args) {
|
}
|
||||||
|
catch (OptionException e) {
|
||||||
if (Argument.Equals ("--disable-gui") || Argument.Equals ("-d"))
|
Console.Write ("SparkleShare: ");
|
||||||
HideUI = true;
|
Console.WriteLine (e.Message);
|
||||||
|
Console.WriteLine ("Try `sparkleshare --help' for more information.");
|
||||||
if (Argument.Equals ("--version") || Argument.Equals ("-v")) {
|
|
||||||
|
|
||||||
PrintVersion ();
|
|
||||||
Environment.Exit (0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Argument.Equals ("--help") || Argument.Equals ("-h")) {
|
if (ShowHelp)
|
||||||
|
DisplayHelp(p);
|
||||||
ShowHelp ();
|
|
||||||
Environment.Exit (0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
SparkleUI = new SparkleUI (HideUI);
|
SparkleUI = new SparkleUI (HideUI);
|
||||||
SparkleUI.Run();
|
SparkleUI.Run();
|
||||||
|
@ -109,9 +104,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
// Prints the help output
|
// Prints the help output
|
||||||
public static void ShowHelp ()
|
public static void DisplayHelp (OptionSet p)
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine (" ");
|
Console.WriteLine (" ");
|
||||||
Console.WriteLine (_("SparkleShare, an instant update workflow to Git."));
|
Console.WriteLine (_("SparkleShare, an instant update workflow to Git."));
|
||||||
Console.WriteLine (_("Copyright (C) 2010 Hylke Bons"));
|
Console.WriteLine (_("Copyright (C) 2010 Hylke Bons"));
|
||||||
|
@ -128,11 +122,8 @@ namespace SparkleShare {
|
||||||
Console.WriteLine (_("Sync SparkleShare folder with remote repositories."));
|
Console.WriteLine (_("Sync SparkleShare folder with remote repositories."));
|
||||||
Console.WriteLine (" ");
|
Console.WriteLine (" ");
|
||||||
Console.WriteLine (_("Arguments:"));
|
Console.WriteLine (_("Arguments:"));
|
||||||
Console.WriteLine (_("\t -d, --disable-gui\tDon't show the notification icon."));
|
p.WriteOptionDescriptions (Console.Out);
|
||||||
Console.WriteLine (_("\t -h, --help\t\tShow this help text."));
|
Environment.Exit (0);
|
||||||
Console.WriteLine (_("\t -v, --version\t\tPrint version information."));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue