Beispiel #1
0
 /// <summary>
 /// Add a default help switch "-help","-h","-?","/help"
 /// </summary>
 public Option AddHelpOption()
 {
     _help = this.AddBoolSwitch("-help", "Command line help");
     _help.AddAlias("-h");
     _help.AddAlias("-?");
     _help.AddAlias("/help");
     return(_help);
 }
        public Command(string[] _args)
        {
            uo = new UrlOperations(this);
            args = _args;
            //create parser
            parser = new CMDLineParser();

            if(_args.Length != 0){
                urlOpt = parser.AddStringParameter("-url", "adress of the website", true);
                if("get".Equals(_args[0]) || "test".Equals(_args[0])){
                    if("get".Equals(_args[0])){
                        getOpt=true;
                        saveOpt = parser.AddStringParameter("-save", "save the content of the website", false);
                    }
                    if("test".Equals(_args[0])){
                        testOpt=true;
                        timesOpt = parser.AddIntParameter("-times", "number of time to load the website", true);
                        avgOpt = parser.AddBoolSwitch("-avg", "average time to load the website");
                    }
                    try{
                        //parse the command line
                        parser.Parse(args);
                    } catch (CMDLineParser.CMDLineParserException ex){
                        getHelp();
                        Console.WriteLine("Error: " + ex.Message);
                        return;
                    }
                    //replace argument list with remaining arguments
                    args = parser.RemainingArgs();
                } else {
                    getHelp();
                  	Console.WriteLine("Error: Missing Required option: 'get' or 'set'");
                  	return;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Add a default help switch "-help","-h","-?","/help"
 /// </summary>
 public Option AddHelpOption()
 {
     _help = this.AddBoolSwitch("-help", "Command line help");
     _help.AddAlias("-h");
     _help.AddAlias("-?");
     _help.AddAlias("/help");
     return (_help);
 }