[smuxi: 139/179] Engine-MessageBuffer: handle missing action correctly
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 139/179] Engine-MessageBuffer: handle missing action correctly
- Date: Sat, 4 Nov 2017 05:49:33 +0000 (UTC)
commit d6d474e2b829c4227bc6e90ece66a6f67e1a3a5e
Author: Mirco Bauer <meebey meebey net>
Date: Tue May 2 18:16:24 2017 +0800
Engine-MessageBuffer: handle missing action correctly
If smuxi-message-buffer was called without an action it is failing with an ugly
exception:
$ smuxi-message-buffer
2017-05-02 18:17:39,529 [Main] FATAL Smuxi.Engine.MainClass - System.InvalidOperationException:
Sequence contains no elements
at System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source)
[0x0006c] in <63992662b765477a898ef49cdcc99ee2>:0
at Smuxi.Engine.MainClass.Main (System.String[] args) [0x000df] in
/tmp/buildd/smuxi-1.0.6/src/Engine-MessageBuffer/Main.cs:76
Instead of that unhandled exception check if the action is missing and if so
show the general command line usage help output.
src/Engine-MessageBuffer/Main.cs | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/src/Engine-MessageBuffer/Main.cs b/src/Engine-MessageBuffer/Main.cs
index 32e31f8..8237542 100644
--- a/src/Engine-MessageBuffer/Main.cs
+++ b/src/Engine-MessageBuffer/Main.cs
@@ -54,14 +54,7 @@ namespace Smuxi.Engine
};
parser.Add("h|help", _("Show this help"),
val => {
- Console.WriteLine(_("Usage: smuxi-message-buffer [options] action action-options"));
- Console.WriteLine();
- Console.WriteLine(_("Actions:"));
- Console.WriteLine(" cat");
- Console.WriteLine(" convert/copy/cp");
- Console.WriteLine();
- Console.WriteLine(_("Options:"));
- parser.WriteOptionDescriptions(Console.Out);
+ ShowUsage(parser);
Environment.Exit(0);
}
);
@@ -73,7 +66,12 @@ namespace Smuxi.Engine
repo.Threshold = log4net.Core.Level.Debug;
}
- var action = args.Skip(mainArgs.Count()).First();
+ var action = args.Skip(mainArgs.Count()).FirstOrDefault();
+ if (String.IsNullOrEmpty(action)) {
+ ShowUsage(parser);
+ Environment.Exit(1);
+ }
+
var actionArgs = args.Skip(mainArgs.Count() + 1);
switch (action.ToLower()) {
case "cat":
@@ -101,6 +99,18 @@ namespace Smuxi.Engine
}
}
+ static void ShowUsage(OptionSet mainOptions)
+ {
+ Console.WriteLine(_("Usage: smuxi-message-buffer [options] action action-options"));
+ Console.WriteLine();
+ Console.WriteLine(_("Actions:"));
+ Console.WriteLine(" cat");
+ Console.WriteLine(" convert/copy/cp");
+ Console.WriteLine();
+ Console.WriteLine(_("Options:"));
+ mainOptions.WriteOptionDescriptions(Console.Out);
+ }
+
static void CatAction(string action, IEnumerable<string> args)
{
var dbFormat = "";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]