Ejemplo n.º 1
0
        public void Interpret(Type baseContext)
        {
            _topContextAttribute = baseContext.GetCustomAttribute(typeof(CmdContextAttribute)) as CmdContextAttribute;
            if (_topContextAttribute is null)
            {
                throw new InvalidCLIConfigurationException("The Type provided has no CmdContextAttribute");
            }

            var contextInterpreter =
                new ContextInterpreter(this, _topContextAttribute)
            {
                UnderlyingContextAttribute = { UnderlyingType = baseContext.GetTypeInfo() }
            };

            contextInterpreter.UnderlyingContextAttribute.Load();
            if (Args.Length > 0)
            {
                if (contextInterpreter.IsParameterEqual(Options.HexOption, Args[0]))
                {
                    HexArgumentEncoding.ArgumentsFromHex(Args[1], out List <string> newArgs);
                    Args = newArgs.ToArray();
                    Interpret(baseContext);

                    return;
                }

                if (contextInterpreter.IsParameterEqual(Options.InteractiveOption, Args[0]))
                {
                    contextInterpreter.IncreaseOffset();
                    contextInterpreter.InteractiveInterpreter(contextInterpreter.Offset < Args.Length);
                }
            }

            try {
                contextInterpreter.Interpret();
            }
            catch (CLIUsageException e) {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException);
                }

                throw;
            }
        }
Ejemplo n.º 2
0
 public void HexArgumentProcessingTests(string[] args, Encoding encoding)
 {
     HexArgumentEncoding.ArgumentsFromHex(HexArgumentEncoding.ToHexArgumentString(args, encoding), out List <string> result);
     Assert.Equal(args, result);
 }