예제 #1
0
 static void Main(string[] args)
 {
     try {
         bool   showHelp   = false;
         string targetXml  = null;
         var    argsParser = new ArgsParser(Path.GetFileName(Environment.GetCommandLineArgs()[0]), "");
         argsParser.AddOption(new ArgOption("?", true, v => showHelp        = true, "print this help"));
         argsParser.AddOption(new ArgOption("x|xml=", false, v => targetXml = v, "save xml to specified file"));
         bool showError = !argsParser.Parse(args, true);
         if (showError || showHelp)
         {
             if (showError)
             {
                 Console.Error.WriteLine("The syntax of the command is incorrect.");
             }
             Console.Write(argsParser.GetUsage());
             if (showError)
             {
                 Environment.Exit(1);
             }
         }
         else
         {
             BurningDiagramTool.Run(targetXml);
         }
     } catch (Exception e) {
         Console.Error.Write(e.ToStringEx());
         Environment.Exit(1);
     }
 }
예제 #2
0
 static void Main(string[] args)
 {
     try {
         bool   showHelp          = false;
         string appKey            = null;
         string userToken         = null;
         string commandName       = null;
         var    commandParameters = new List <string>();
         var    argsParser        = new ArgsParser(Path.GetFileName(Environment.GetCommandLineArgs()[0]), "<command> <command parameters>");
         argsParser.AddOption(new ArgOption("?", true, v => showHelp              = true, "print this help"));
         argsParser.AddOption(new ArgOption("k|appkey=", false, v => appKey       = v, "application key"));
         argsParser.AddOption(new ArgOption("u|usertoken=", false, v => userToken = v, "user token"));
         argsParser.AddTarget(new ArgTarget(false, s => { commandName = s; return(true); }));
         argsParser.AddTarget(new ArgTarget(false, s => { commandParameters.Add(s); return(false); }));
         bool          showError = !argsParser.Parse(args, true);
         TrelloCommand?command   = null;
         if (!showError && !showHelp)
         {
             command = ParseCommand(commandName, commandParameters);
             if (command == null)
             {
                 showError = true;
             }
         }
         if (showError || showHelp || command == null)
         {
             if (showError)
             {
                 Console.Error.WriteLine("The syntax of the command is incorrect.");
             }
             Console.WriteLine(argsParser.GetUsage());
             Console.WriteLine("Known commands:");
             Console.WriteLine("\tgbd <board name> - get burndown chart data");
             Console.WriteLine("\tpbc <board name> [<image file>] - put burndown chart picture from specified file or standard input");
             if (showError)
             {
                 Environment.Exit(1);
             }
         }
         else
         {
             TrelloTool.Run(appKey, userToken, command.Value, commandParameters);
         }
     } catch (Exception e) {
         Console.Error.Write(e.ToStringEx());
         Environment.Exit(1);
     }
 }
예제 #3
0
 /// <summary>
 /// Adds a command to the list, and optionally, adds the command to the given <see cref="ArgsParser"/> (to same time)
 /// <para>
 /// Message format when writing: (replace the dots with whitespaces)
 /// </para>
 /// <code>
 ///   ..-[option] [parameter descritpion]
 ///   <code>
 ///   .....[extra info]
 ///   </code>
 /// </code>
 /// </summary>
 /// <param name="option"></param>
 /// <param name="parameter"></param>
 /// <param name="description"></param>
 /// <param name="parser"></param>
 public void AddCommand(string option, ParameterType parameter, string description, ArgsParser parser = null)
 {
     Commands.Add($"  -{option} [{parameter.GetReadableName()}]\n     {description}");
     if (parser != null)
     {
         parser.AddOption(option, parameter);
     }
 }