csharp-s6ts
authorSparky6 <sparky6@core>
Fri, 26 May 2023 21:41:42 +0000 (23:41 +0200)
committerSparky6 <sparky6@core>
Fri, 26 May 2023 21:41:42 +0000 (23:41 +0200)
csharp/mDoc/Program.cs
debian/mdoc-tools.changelog

index 39110a2..419b75a 100644 (file)
@@ -4,37 +4,52 @@ using System;
 using mDoc;\r
 \r
 class mDocMain{\r
-    static int command_dispatch(string[] args) {\r
+    static int Main(string[] args) {\r
+\r
+        Console.WriteLine("mdoc");\r
+        string usage = "mdoc [options] <source> <target-format>";\r
 \r
         // check runtime parameters\r
-        if (args.Length < 2) throw new ApplicationException("mdoc needs 2 arguments.");\r
-        \r
+        if (args.Length < 2) {\r
+            Console.WriteLine("mdoc needs 2 arguments.");\r
+            return 1;\r
+        }\r
+\r
+        string opts;\r
         string file = args[0];\r
         string template = args[1];\r
-        \r
-        Worker w = new Worker();\r
-        return w.convert(file, template);\r
-    }\r
-    public static int Main(string[] argv){\r
-        Console.WriteLine("mdoc");\r
 \r
-        string usage = "mdoc <source> <target-format>";\r
+        // define options\r
+        bool verbose = false;\r
 \r
-        if (argv.Length < 1) {\r
-            Console.WriteLine(usage);\r
-            return 1;\r
-        }\r
+        try{\r
+            if (args.Length == 3) {\r
+                opts = args[0];\r
+                file = args[1];\r
+                template = args[2];\r
 \r
-        try {\r
-            int ret = command_dispatch(argv);\r
+                // check options\r
+                if (opts[0] != '-') throw new ApplicationException("Options have to start with an '-'.");\r
+                for (int i=1; i<opts.Length; i++ ) {\r
+                    switch (opts[i]) {\r
+                        case 'v': verbose = true;\r
+                            break;\r
+                        default: throw new ApplicationException("Unknown options: "+opts[i]);\r
+                    }\r
+                }\r
+            }\r
+            \r
+            Worker w = new Worker();\r
+            int ret = w.convert(file, template);\r
             if (ret != 0) {\r
-                Console.WriteLine(usage);\r
+                Console.WriteLine("Worker returned: " + Convert.ToString(ret));\r
             }\r
-            return ret;\r
         }\r
         catch (Exception e) {\r
-            Console.WriteLine(e.ToString());\r
-            throw new Exception(e.ToString());\r
+            if (verbose) Console.WriteLine(e.ToString());\r
+            else Console.WriteLine(e.Message);\r
+            return 99;\r
         }\r
+        return 0;\r
     }\r
 }\r
index 9f018e5..983c899 100644 (file)
@@ -1,4 +1,7 @@
+mdoc (0.2-%BUILD%) unstable; urgency=medium
+  * better error messages
+ -- Michael Wagner <michael@wagnertech.de>  Fri,  26 May 2023 16:54:48 +0100
+
 mdoc (0.1-%BUILD%) unstable; urgency=medium
   * C# port for mmailc
  -- Michael Wagner <michael@wagnertech.de>  Fri,  30 Dec 2022 16:54:48 +0100
-