public int Try()
        {
            var theUsageWriter = new CmdLineUsageWriter(myDefinition);

            if (myDefinition.HasDifferentiatedSubcommands && !myDefinition.Subcommands.Any())
            {
                throw new InvalidOperationException("At least one subcommand must be added to the definition.");
            }

            if (myDefinition.HasDifferentiatedSubcommands && myArgs.Length < 1)
            {
                theUsageWriter.WriteAndExit();
                return(-1);
            }

            // Default Command suchen
            CmdLineSubcommand?theSubcommand = myDefinition.Subcommands.SingleOrDefault(
                sc => sc.Name == CmdLineSubcommand.DefaultName
                );

            if (!myDefinition.HasDifferentiatedSubcommands && theSubcommand == null)
            {
                throw new InvalidOperationException(
                          "Without differentiated commands a subcommand with the name \"default\" must be added to the definition."
                          );
            }

            // Token-List erstellen und passenden Subcommand ermitteln (im Fehlerfall wird
            // hier die Usage erklärt und mit ReturnCode -1 der Prozess beendet)
            var theTokenizer = new CmdLineTokenizer(myDefinition, theUsageWriter);
            List <CmdLineToken> theTokens = theTokenizer.Tokenize(myArgs, ref theSubcommand);

            // Subcommand ausführen
            return(theSubcommand !.Execute(theTokens, myDefinition));
        }
        /// <summary>Writes the usage help for the specified subcommand to
        /// the console.</summary>
        /// <param name="subcommandName">Name of the subcommand</param>
        public void ShowHelp(string subcommandName)
        {
            if (subcommandName == null)
            {
                throw new ArgumentNullException(nameof(subcommandName));
            }

            CmdLineSubcommand theSubcommand = Subcommands.SingleOrDefault(sc => sc.Name == subcommandName);

            if (theSubcommand == null)
            {
                throw new ArgumentException($"Subcommand \"{subcommandName}\" is not defined.");
            }

            var theUsageWriter = new CmdLineUsageWriter(this);

            theUsageWriter.WriteAndExit(theSubcommand);
        }
        /// <summary>Writes the usage help to the console.</summary>
        public void ShowHelp()
        {
            var theUsageWriter = new CmdLineUsageWriter(this);

            theUsageWriter.WriteAndExit();
        }
 public CmdLineTokenizer(CmdLineDefinition definition, CmdLineUsageWriter usageWriter)
 {
     myDefinition  = definition;
     myUsageWriter = usageWriter;
 }