예제 #1
0
        public bool Process(string[] args)
        {
            Console.WriteLine("{0} - {1}\r\n", AppName, Caption);
            
            RemainingArgs = ExpectRemainingParameters();
            CurrentArgMethod = DefaultProcessFunc;
            ExpectedArg = null;


            foreach (string arg in args)
            {
                if (!CurrentArgMethod(arg))
                    return false;
            }

            if (!AreAllRequiredArgumentsPresent())
                return false;

            return true;
        }
예제 #2
0
        public bool Process(string[] args)
        {
            Console.WriteLine("{0} - {1}\r\n", AppName, Caption);

            RemainingArgs    = ExpectRemainingParameters();
            CurrentArgMethod = DefaultProcessFunc;
            ExpectedArg      = null;


            foreach (string arg in args)
            {
                if (!CurrentArgMethod(arg))
                {
                    return(false);
                }
            }

            if (!AreAllRequiredArgumentsPresent())
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
 private bool ExpectStringList(ref string arg)
 {
     List<string> items = new List<string>();
     foreach (string s in arg.Split(';'))
     {
         items.Add(s);
     }
     ExpectedArg.Value = items;
     ExpectedArg.HasBeenSeen = true;
     CurrentArgMethod = DefaultProcessFunc;
     return true;
 }
예제 #4
0
 private bool ExpectParameter(ref string arg)
 {
     ExpectedArg.Value = arg;
     ExpectedArg.HasBeenSeen = true;
     CurrentArgMethod = DefaultProcessFunc;
     return true;
 }
예제 #5
0
 private bool ExpectNewDirectory(ref string arg)
 {
     ExpectedArg.Value = arg;
     ExpectedArg.HasBeenSeen = true;
     /*
      * If you use double quotes on a command line argument and end in a \ the string gets passed as
      * ending in ". e.g if you issue the command [pathed /add "c:\program files\foo\"], the last
      * argument gets passed as [c:\program files\foo"]. This is because windows tries to be forgiving
      * about spaces, but the '\' escapes a double quote.
      */
     if (arg.EndsWith("\""))
         arg = arg.Remove(arg.LastIndexOf('"'));
     // Its just a waste of a character in your path.
     if (arg.EndsWith("\\"))
         arg = arg.Remove(arg.LastIndexOf('\\'));
     if (!Directory.Exists(arg))
     {
         Console.WriteLine("ERROR, argument {0} must specify an existing directory, '{1}' does not exist.", ExpectedArg.Name, arg);
         return false;
     }
     CurrentArgMethod = DefaultProcessFunc;
     return true;
 }
예제 #6
0
        internal virtual bool OnProcessOption(InputArg option, string arg)
        {
            switch (option.Type)
            {
                case InputArgType.ExistingDirectory:
                    ExpectedArg = option;
                    CurrentArgMethod = ExpectNewDirectory;
                    return true;

                case InputArgType.Parameter:
                    ExpectedArg = option;
                    CurrentArgMethod = ExpectParameter;
                    return true;

                case InputArgType.StringList:
                    ExpectedArg = option;
                    CurrentArgMethod = ExpectStringList;
                    return true;

                case InputArgType.Flag:
                    option.Value = true;
                    option.HasBeenSeen = true;
                    CurrentArgMethod = DefaultProcessFunc;
                    return true;

                default:
                    Console.WriteLine("Error, argument type {0} not implemented yet.", option.Type);
                    return false;
            }
        }
예제 #7
0
        public bool Process(ref string[] args)
        {
            Console.WriteLine("{0} - {1}\r\n", AppName, Caption);

            RemainingArgs = ExpectRemainingParameters();
            CurrentArgMethod = DefaultProcessFunc;
            ExpectedArg = null;

            for (int i = 0; i < args.Length; i++ )
            {
                if (!CurrentArgMethod(ref args[i]))
                    return false;
            }

            if (!AreAllRequiredArgumentsPresent())
                return false;

            return true;
        }
예제 #8
0
        private bool ExpectSizeInBytes(string arg)
        {
            decimal sizeAsDecimal      = 0.0m;
            string  digits             = "0123456789";
            bool    recording_fraction = false;
            decimal fraction_divisor   = 0.0m;
            bool    expectByte         = false;

            for (int i = 0; i < arg.Length; ++i)
            {
                char c     = arg[i];
                int  digit = digits.IndexOf(c);

                if (expectByte)
                {
                    if ((c == 'b') || (c == 'B'))
                    {
                        expectByte = true;
                    }
                    else
                    {
                        Console.WriteLine("ERROR, '{0}' is not a valid size indicator", arg);
                        return(false);
                    }
                }
                else if (digit >= 0)
                {
                    if (recording_fraction)
                    {
                        sizeAsDecimal    += ((decimal)digit) / fraction_divisor;
                        fraction_divisor *= 10.0m;
                    }
                    sizeAsDecimal *= 10.0m;
                    sizeAsDecimal += digit;
                }
                else if (c == '.')
                {
                    recording_fraction = true;
                    fraction_divisor   = 10.0m;
                }
                else if ((c == 'k') || (c == 'K'))
                {
                    sizeAsDecimal *= 1024;
                    expectByte     = true;
                }
                else if ((c == 'm') || (c == 'm'))
                {
                    sizeAsDecimal *= 1024 * 1024;
                    expectByte     = true;
                }
                else if ((c == 'g') || (c == 'g'))
                {
                    sizeAsDecimal *= 1024 * 1024 * 1024;
                    expectByte     = true;
                }
                else if (c != ' ')
                {
                    Console.WriteLine("ERROR, '{0}' is not a valid size indicator", arg);
                    return(false);
                }
            }
            long sizeInBytes = (long)sizeAsDecimal;

            ExpectedArg.Value       = sizeInBytes;
            ExpectedArg.HasBeenSeen = true;
            CurrentArgMethod        = DefaultProcessFunc;
            return(true);
        }
예제 #9
0
 private bool ExpectNewDirectory(string arg)
 {
     ExpectedArg.Value = arg;
     ExpectedArg.HasBeenSeen = true;
     if (!Directory.Exists(arg))
     {
         Console.WriteLine("ERROR, argument {0} must specify an existing directory, '{1}' does not exist.", ExpectedArg.Name, arg);
         return false;
     }
     CurrentArgMethod = DefaultProcessFunc;
     return true;
 }
예제 #10
0
        private bool ExpectSizeInBytes(string arg)
        {
            decimal sizeAsDecimal = 0.0m;
            string digits = "0123456789";
            bool recording_fraction = false;
            decimal fraction_divisor = 0.0m;
            bool expectByte = false;

            for (int i = 0; i < arg.Length; ++i)
            {
                char c = arg[i];
                int digit = digits.IndexOf(c);

                if (expectByte)
                {
                    if ((c == 'b') || (c == 'B'))
                    {
                        expectByte = true;
                    }
                    else
                    {
                        Console.WriteLine("ERROR, '{0}' is not a valid size indicator", arg);
                        return false;
                    }
                }
                else if (digit >= 0)
                {
                    if (recording_fraction)
                    {
                        sizeAsDecimal += ((decimal)digit) / fraction_divisor;
                        fraction_divisor *= 10.0m;
                    }
                    sizeAsDecimal *= 10.0m;
                    sizeAsDecimal += digit;
                }
                else if( c == '.' )
                {
                    recording_fraction = true;
                    fraction_divisor = 10.0m;
                }
                else if ((c == 'k') || (c == 'K'))
                {
                    sizeAsDecimal *= 1024;
                    expectByte = true;
                }
                else if ((c == 'm') || (c == 'm'))
                {
                    sizeAsDecimal *= 1024 * 1024;
                    expectByte = true;
                }
                else if ((c == 'g') || (c == 'g'))
                {
                    sizeAsDecimal *= 1024 * 1024 * 1024;
                    expectByte = true;
                }
                else if (c != ' ')
                {
                    Console.WriteLine("ERROR, '{0}' is not a valid size indicator", arg);
                    return false;
                }
            }
            long sizeInBytes = (long)sizeAsDecimal;
            ExpectedArg.Value = sizeInBytes;
            ExpectedArg.HasBeenSeen = true;
            CurrentArgMethod = DefaultProcessFunc;
            return true;
        }
예제 #11
0
 private bool ExpectMultipleParameters(string arg)
 {
     List<string> result = FindOrCreateStringList(CurrentOption.Name);
     result.Add(arg);
     CurrentArgMethod = DefaultProcessFunc;
     return true;
 }