Simplify command line argument parsing
This commit is contained in:
parent
07c4d271e3
commit
7ceb17907d
|
@ -44,7 +44,6 @@
|
||||||
<Compile Include="SparkleAnnouncement.cs" />
|
<Compile Include="SparkleAnnouncement.cs" />
|
||||||
<Compile Include="SparkleHelpers.cs" />
|
<Compile Include="SparkleHelpers.cs" />
|
||||||
<Compile Include="SparklePaths.cs" />
|
<Compile Include="SparklePaths.cs" />
|
||||||
<Compile Include="SparkleOptions.cs" />
|
|
||||||
<Compile Include="SparkleChangeSet.cs" />
|
<Compile Include="SparkleChangeSet.cs" />
|
||||||
<Compile Include="SparkleListenerBase.cs" />
|
<Compile Include="SparkleListenerBase.cs" />
|
||||||
<Compile Include="SparkleListenerFactory.cs" />
|
<Compile Include="SparkleListenerFactory.cs" />
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [[ $UID -eq 0 ]]; then
|
if [[ $UID -eq 0 ]]; then
|
||||||
echo "Cannot run as root. Things would go utterly wrong."
|
echo "SparkleShare can't be run as root. Things would go utterly wrong."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ start() {
|
||||||
echo "SparkleShare is already running."
|
echo "SparkleShare is already running."
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "SparkleShare stale pid file found, starting a new instance."
|
echo "Stale SparkleShare PID file found, starting a new instance..."
|
||||||
rm -f $pidfile
|
rm -f $pidfile
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -42,7 +42,7 @@ stop() {
|
||||||
rm -f ${pidfile}
|
rm -f ${pidfile}
|
||||||
echo "Done."
|
echo "Done."
|
||||||
else
|
else
|
||||||
echo "SparkleShare is not running, removing stale pid file..."
|
echo "SparkleShare is not running, removing stale PID file..."
|
||||||
rm -f ${pidfile}
|
rm -f ${pidfile}
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -65,13 +65,7 @@ case $1 in
|
||||||
invite=`date -u +%N`
|
invite=`date -u +%N`
|
||||||
curl -o ~/SparkleShare/$invite.xml `echo $2 | sed s/sparkleshare:/https:/`
|
curl -o ~/SparkleShare/$invite.xml `echo $2 | sed s/sparkleshare:/https:/`
|
||||||
;;
|
;;
|
||||||
help|--help|-h)
|
*)
|
||||||
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
||||||
;;
|
;;
|
||||||
version|--version|-v)
|
|
||||||
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --version
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: sparkleshare {start|stop|restart|help|version}"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -94,9 +94,6 @@
|
||||||
<Compile Include="..\SparklePlugin.cs">
|
<Compile Include="..\SparklePlugin.cs">
|
||||||
<Link>SparklePlugin.cs</Link>
|
<Link>SparklePlugin.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\SparkleOptions.cs">
|
|
||||||
<Link>SparkleOptions.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="SparkleAbout.cs" />
|
<Compile Include="SparkleAbout.cs" />
|
||||||
<Compile Include="..\SparkleInvite.cs">
|
<Compile Include="..\SparkleInvite.cs">
|
||||||
<Link>SparkleInvite.cs</Link>
|
<Link>SparkleInvite.cs</Link>
|
||||||
|
|
|
@ -17,7 +17,6 @@ SOURCES = \
|
||||||
SparkleEventLogController.cs \
|
SparkleEventLogController.cs \
|
||||||
SparkleExtensions.cs \
|
SparkleExtensions.cs \
|
||||||
SparkleInvite.cs \
|
SparkleInvite.cs \
|
||||||
SparkleOptions.cs \
|
|
||||||
SparklePlugin.cs \
|
SparklePlugin.cs \
|
||||||
SparkleSetupController.cs \
|
SparkleSetupController.cs \
|
||||||
SparkleStatusIconController.cs
|
SparkleStatusIconController.cs
|
||||||
|
|
|
@ -21,7 +21,6 @@ using System.Threading;
|
||||||
#if __MonoCS__
|
#if __MonoCS__
|
||||||
using Mono.Unix;
|
using Mono.Unix;
|
||||||
#endif
|
#endif
|
||||||
using SparkleLib;
|
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
@ -30,18 +29,18 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public static SparkleController Controller;
|
public static SparkleController Controller;
|
||||||
public static SparkleUI UI;
|
public static SparkleUI UI;
|
||||||
|
|
||||||
public static Mutex ProgramMutex = new Mutex (false, "SparkleShare");
|
private static Mutex program_mutex = new Mutex (false, "SparkleShare");
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
public static string _ (string s)
|
public static string _ (string s)
|
||||||
{
|
{
|
||||||
#if __MonoCS__
|
#if __MonoCS__
|
||||||
return Catalog.GetString (s);
|
return Catalog.GetString (s);
|
||||||
#else
|
#else
|
||||||
return Strings.T (s);
|
return Strings.T (s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,33 +49,30 @@ namespace SparkleShare {
|
||||||
#endif
|
#endif
|
||||||
public static void Main (string [] args)
|
public static void Main (string [] args)
|
||||||
{
|
{
|
||||||
// Parse the command line options
|
if (args.Length != 0 && !args [0].Equals ("start")) {
|
||||||
bool show_help = false;
|
Console.WriteLine (" ");
|
||||||
OptionSet option_set = new OptionSet () {
|
Console.WriteLine ("SparkleShare is a collaboration and sharing tool that is ");
|
||||||
{ "v|version", _("Print version information"), v => { PrintVersion (); } },
|
Console.WriteLine ("designed to keep things simple and to stay out of your way.");
|
||||||
{ "h|help", _("Show this help text"), v => show_help = v != null }
|
Console.WriteLine (" ");
|
||||||
};
|
Console.WriteLine ("Version: " + SparkleLib.Defines.VERSION);
|
||||||
|
Console.WriteLine ("Copyright (C) 2010 Hylke Bons");
|
||||||
|
Console.WriteLine (" ");
|
||||||
|
Console.WriteLine ("This program comes with ABSOLUTELY NO WARRANTY.");
|
||||||
|
Console.WriteLine (" ");
|
||||||
|
Console.WriteLine ("This is free software, and you are welcome to redistribute it ");
|
||||||
|
Console.WriteLine ("under certain conditions. Please read the GNU GPLv3 for details.");
|
||||||
|
Console.WriteLine (" ");
|
||||||
|
Console.WriteLine ("Usage: sparkleshare [start|stop|restart]");
|
||||||
|
|
||||||
try {
|
Environment.Exit (-1);
|
||||||
option_set.Parse (args);
|
|
||||||
|
|
||||||
} catch (OptionException e) {
|
|
||||||
Console.Write ("SparkleShare: ");
|
|
||||||
Console.WriteLine (e.Message);
|
|
||||||
Console.WriteLine ("Try `sparkleshare --help' for more information.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_help)
|
|
||||||
ShowHelp (option_set);
|
|
||||||
|
|
||||||
|
|
||||||
// Only allow one instance of SparkleShare
|
// Only allow one instance of SparkleShare (on Windows)
|
||||||
if (!ProgramMutex.WaitOne (0, false)) {
|
if (!program_mutex.WaitOne (0, false)) {
|
||||||
Console.WriteLine ("SparkleShare is already running.");
|
Console.WriteLine ("SparkleShare is already running.");
|
||||||
Environment.Exit (-1);
|
Environment.Exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize the controller this way so that
|
// Initialize the controller this way so that
|
||||||
// there aren't any exceptions in the OS specific UI's
|
// there aren't any exceptions in the OS specific UI's
|
||||||
Controller = new SparkleController ();
|
Controller = new SparkleController ();
|
||||||
|
@ -93,37 +89,5 @@ namespace SparkleShare {
|
||||||
GC.WaitForPendingFinalizers ();
|
GC.WaitForPendingFinalizers ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prints the help output
|
|
||||||
public static void ShowHelp (OptionSet option_set)
|
|
||||||
{
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("SparkleShare, a collaboration and sharing tool."));
|
|
||||||
Console.WriteLine (_("Copyright (C) 2010 Hylke Bons"));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("This program comes with ABSOLUTELY NO WARRANTY."));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("This is free software, and you are welcome to redistribute it "));
|
|
||||||
Console.WriteLine (_("under certain conditions. Please read the GNU GPLv3 for details."));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("SparkleShare is a collaboration and sharing tool that is "));
|
|
||||||
Console.WriteLine (_("designed to keep things simple and to stay out of your way."));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("Usage: sparkleshare [start|stop|restart|version] [OPTION]..."));
|
|
||||||
Console.WriteLine (_("Sync SparkleShare folder with remote repositories."));
|
|
||||||
Console.WriteLine (" ");
|
|
||||||
Console.WriteLine (_("Arguments:"));
|
|
||||||
|
|
||||||
option_set.WriteOptionDescriptions (Console.Out);
|
|
||||||
Environment.Exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void PrintVersion ()
|
|
||||||
{
|
|
||||||
Console.WriteLine (_("SparkleShare " + Defines.VERSION));
|
|
||||||
Environment.Exit (0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -263,8 +263,7 @@ namespace SparkleShare {
|
||||||
full_name = full_name.Trim ();
|
full_name = full_name.Trim ();
|
||||||
email = email.Trim ();
|
email = email.Trim ();
|
||||||
|
|
||||||
bool fields_valid = (full_name != null &&
|
bool fields_valid = (!string.IsNullOrEmpty (full_name) &&
|
||||||
full_name.Trim ().Length > 0 &&
|
|
||||||
IsValidEmail (email));
|
IsValidEmail (email));
|
||||||
|
|
||||||
if (UpdateSetupContinueButtonEvent != null)
|
if (UpdateSetupContinueButtonEvent != null)
|
||||||
|
@ -381,10 +380,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
this.saved_remote_path = remote_path;
|
this.saved_remote_path = remote_path;
|
||||||
|
|
||||||
bool fields_valid = (address != null &&
|
bool fields_valid = (!string.IsNullOrEmpty (address) &&
|
||||||
address.Trim ().Length > 0 &&
|
!string.IsNullOrEmpty (remote_path) &&
|
||||||
remote_path != null &&
|
|
||||||
remote_path.Trim ().Length > 0 &&
|
|
||||||
!remote_path.Contains ("\""));
|
!remote_path.Contains ("\""));
|
||||||
|
|
||||||
if (UpdateAddProjectButtonEvent != null)
|
if (UpdateAddProjectButtonEvent != null)
|
||||||
|
|
|
@ -90,9 +90,6 @@
|
||||||
<Compile Include="..\SparkleInvite.cs">
|
<Compile Include="..\SparkleInvite.cs">
|
||||||
<Link>SparkleInvite.cs</Link>
|
<Link>SparkleInvite.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\SparkleOptions.cs">
|
|
||||||
<Link>SparkleOptions.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\SparklePlugin.cs">
|
<Compile Include="..\SparklePlugin.cs">
|
||||||
<Link>SparklePlugin.cs</Link>
|
<Link>SparklePlugin.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -451,4 +448,4 @@
|
||||||
<Content Include="..\..\data\icons\sparkleshare.ico" />
|
<Content Include="..\..\data\icons\sparkleshare.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue