Beispiel #1
0
        public CommandLineParseResult Parse(string[] args)
        {
            ParserResult <object> result =
                Parser.Default.ParseArguments <ConfigureOptions, DrawOptions, FetchOptions>(args);

            if (result is NotParsed <object> )
            {
                IEnumerable <Error> errors = (result as NotParsed <object>).Errors;
                foreach (Error error in errors)
                {
                    _log.Error("Invalid command line arguments ({0}).", error.Tag);
                }

                return(CommandLineParseResult.Failed);
            }

            var          parsed  = (Parsed <object>)result;
            IVerbOptions options = parsed.Value as IVerbOptions;

            if (options == null)
            {
                string message = "Unexpected problem parsing command line.";
                _log.Fatal(message);
                throw new LoggedAsFatalException(message);
            }

            Verb v = GetVerbFrom(options);
            IVerbOptionsConverter converter     = _factories[v];
            IVerbRunnerOptions    runnerOptions = converter.ConvertOptions(options);

            return(CommandLineParseResult.Correct(v, runnerOptions));
        }
Beispiel #2
0
        private Verb GetVerbFrom(IVerbOptions parsed)
        {
            VerbAttribute verbAttribute = parsed.GetType().GetCustomAttribute <VerbAttribute>();
            string        verbName      = verbAttribute.Name;
            Verb          verb          = VerbHelper.FromName(verbName);

            return(verb);
        }
Beispiel #3
0
        public void Process(IVerbOptions obj)
        {
            var options = obj as Options;

            using (var stream = new FileStream(options.File, FileMode.Open, FileAccess.ReadWrite)) {
                this.ProcessInternal(stream);
            }
        }
Beispiel #4
0
        public void Process(IVerbOptions obj)
        {
            var options = obj as Options;

            var targetId = string.IsNullOrEmpty(options.TargetId) ? -1 : options.TargetId.ToInt32(0, 255);

            using (var stream = new FileStream(options.File, FileMode.Open, FileAccess.ReadWrite)) {
                this.ProcessInternal(stream, targetId);
            }
        }
Beispiel #5
0
        public void Process(IVerbOptions obj)
        {
            var options = obj as Options;

            var setDevice  = options.SetDevice.ToInt32(0, 0xffff);
            var setProduct = options.SetProduct.ToInt32(0, 0xffff);
            var setVendor  = options.SetVendor.ToInt32(0, 0xffff);

            using (var stream = new FileStream(options.File, FileMode.Create, FileAccess.ReadWrite)) {
                this.ProcessInternal(stream, setDevice, setProduct, setVendor);
            }
        }
Beispiel #6
0
        public void Process(IVerbOptions obj)
        {
            var options = obj as Options;

            var targetId          = string.IsNullOrEmpty(options.TargetId) ? -1 : options.TargetId.ToInt32(0, 255);
            var setElementAddress =
                string.IsNullOrEmpty(options.SetElementAddress) ? 0xffffffffu : options.SetElementAddress.ToUInt32();
            var setElementFile = options.SetElementFile;

            if (!File.Exists(setElementFile))
            {
                throw new ArgumentException("Element's file was not found!");
            }

            using (var dfuStream = new FileStream(options.File, FileMode.Open, FileAccess.ReadWrite)) {
                using (var elementStream = new FileStream(setElementFile, FileMode.Open, FileAccess.Read)) {
                    this.ProcessInternal(dfuStream, targetId, setElementAddress, elementStream);
                }
            }
        }
        public IVerbRunnerOptions ConvertOptions(IVerbOptions source)
        {
            TTarget result = ConvertOptionsInternal((TSource)source);

            return(result);
        }