Exemple #1
0
        public void WithoutOptionalFlagIsSuccessful()
        {
            CmdFlag[] allowedFlags = { new CmdFlag("i", true), new CmdFlag("o", true), new CmdFlag("v", false) };
            CmdLine   cmd          = new CmdLine(allowedFlags);

            string[] args    = { @"-ie:\data\dl\test.txt", @"-oe:\data\dl\test.out" };
            bool     success = cmd.ProcessCmdLine(args); // parse the command line

            Assert.IsTrue(success, "success is false");
            Assert.IsTrue(cmd.ParmExists("o"), "parm o does not exist");
            Assert.AreEqual(@"e:\data\dl\test.out", cmd.GetParm("o"), "parm 'o' does not match");
            Assert.IsTrue(cmd.ParmExists("i"), "parm o does not exist");
            Assert.AreEqual(@"e:\data\dl\test.txt", cmd.GetParm("i"), "parm 'i' does not match");
            Assert.IsFalse(cmd.ParmExists("v"), "parm v exists");
            Assert.IsFalse(cmd.ParmExists("O"), "parm O exists");
        }
Exemple #2
0
 public CmdlineHelper(string[] args)
 {
     ReturnPackage     = null;
     CmdErrorCode      = 0;
     CmdLineParser     = null;
     AllParmsPresent   = false;
     RunViaCommandLine = args.Length > 0;
     // if command line parms, process them
     if (RunViaCommandLine)
     {
         CmdFlag[] flags =
         {
             new CmdFlag(CmdLineParm_JobID,         true), // required parm
             new CmdFlag(CmdLineParm_SimMode,       false),
             new CmdFlag(CmdLineParm_DebugMode,     false),
             new CmdFlag(CmdLineParm_ShowLogFile,   false),
             new CmdFlag(CmdLineParm_ShowErrorFile, false),
             new CmdFlag(CmdLineParm_ShowDebugFile, false),
             new CmdFlag(CmdLineParm_ExportConfig,  false)
         };
         CmdLineParser   = new CmdLine(flags);
         AllParmsPresent = CmdLineParser.ProcessCmdLine(args);
         if (AllParmsPresent)
         {
             // validate Job ID is numeric
             string jobStr = CmdLineParser.GetParm(CmdLineParm_JobID);
             int    jobID;
             if (int.TryParse(jobStr, out jobID) == false)
             {
                 CmdErrorCode = AppError_CmdLineJobIDNotNumeric;
                 return;
             }
             bool debugMode = CmdLineParser.ParmExists(CmdLineParm_DebugMode);
             ReturnPackage = new CmdLineParmRet {
                 JobID         = jobID,
                 RunInSimMode  = CmdLineParser.ParmExists(CmdLineParm_SimMode),
                 DebugMode     = debugMode,
                 ShowErrFile   = CmdLineParser.ParmExists(CmdLineParm_ShowErrorFile),
                 ShowLogFile   = CmdLineParser.ParmExists(CmdLineParm_ShowLogFile),
                 ExportConfig  = CmdLineParser.ParmExists(CmdLineParm_ExportConfig),
                 ShowDebugFile = debugMode ? CmdLineParser.ParmExists(CmdLineParm_ShowDebugFile) : false
             };
         }
         else
         {
             CmdErrorCode = AppError_CmdLineParseFailed;
         }
     }
 }