Esempio n. 1
0
        static int Main(string[] args)
        {
            var ddNode = new DDNode(DrCmdConst.TypeSettings, DrCmdConst.TypeSettings);

            ddNode.Attributes.Add(DrCmdSettings.ApplicationDescription, "It's test application.");
            ddNode.Add(GetCommandHelp());
            ddNode.Add(GetCommandTest());
            ddNode.Add(GetCommandSignFile());
            ddNode.Add(GetCommandSign());
            ddNode.Add(GetCommandStat());
            ddNode.Add(GetCommandBenchmark());
            SerializeConfig(ddNode);

            var cmd = new DrCmdParser(ddNode);


            ddNode.Attributes.Add(DrCmdSettings.Arguments, args, ResolveConflict.OVERWRITE);

            try
            {
                var res = cmd.Parse();
                if (string.Compare(res.Name, CmdCommandNameHelp, true) == 0)
                {
                    Console.Write(cmd.GetHelp(true)); // show full help
                    return(ExitCodeHelpInfo);
                }
            }
            catch (Exception e)
            {
                if (cmd.ActiveCommnand == null)
                {
                    if ((args != null) && (args.Length > 0))
                    {
                        Console.WriteLine(GetExceptionAsString(e)); // if command line is empty
                        Console.WriteLine();
                    }
                    Console.Write(cmd.GetHelp(false)); // show command help only
                    return(ExitCodeInvalidCommand);
                }

                bool isSpecifiedCmdHelp = (cmd.ActiveCommnand.Contains("?") ? cmd.ActiveCommnand.GetNode("?").Attributes.GetValue(DrCmdOptionSettings.ResultIsOptionSpecified, false).GetValueAsBool() : false); // if specified option '-?' for active command

                if (!isSpecifiedCmdHelp)
                {
                    Console.WriteLine(GetExceptionAsString(e));
                    Console.WriteLine();
                    Console.Write(cmd.GetHelpForActiveCommand()); // show active command help only
                    return(ExitCodeInvalidCommandOptions);
                }
                Console.Write(cmd.GetHelpForActiveCommand()); // show active command help only
                return(ExitCodeHelpInfo);
            }
            return(ExitCodeOK);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var ddNode = new DDNode(DrCmdConst.TypeSettings, new DDType(DrCmdConst.TypeSettings));

            ddNode.Attributes.Add(DrCmdSettings.ApplicationDescription, "Converters binary file from smart snail project.");
            ddNode.Add(GetCommandTXT());
            ddNode.Add(GetCommandBIN());
            ddNode.Attributes.Add(DrCmdSettings.Arguments, args, ResolveConflict.OVERWRITE);
            var cmd = new DrCmdParser(ddNode);

            try
            {
                var res = cmd.Parse();
            }
            catch (Exception e)
            {
                if (cmd.ActiveCommnand == null)
                {
                    if ((args != null) && (args.Length > 0))
                    {
                        Console.WriteLine(GetExceptionAsString(e)); // if command line is empty
                        Console.WriteLine();
                    }
                    Console.Write(cmd.GetHelp(false)); // show command help only
                }
                else
                {
                    Console.WriteLine(GetExceptionAsString(e));
                    Console.WriteLine();
                    Console.Write(cmd.GetHelpForActiveCommand()); // show active command help only
                }
            }

            if (cmd.ActiveCommnand.Name == "BIN")
            {
                ConvertFromBin(cmd.ActiveCommnand["s"].Attributes["Value"], cmd.ActiveCommnand["d"].Attributes["Value"]);
            }
            if (cmd.ActiveCommnand.Name == "TXT")
            {
                ConvertFromTxt(cmd.ActiveCommnand["s"].Attributes["Value"], cmd.ActiveCommnand["d"].Attributes["Value"]);
            }
        }