Ejemplo n.º 1
0
        private void GetCommandLineConfiguration(string[] args)
        {
            var docopt = new Docopt();

            IDictionary<string, ValueObject> res = docopt.Apply(Usage, args, help: true, exit: true);

            _ocdmModelExportPath = res["--modelExport"] == null ? _ocdmModelExportPath : res["--modelExport"].ToString();

            _readerName = res["--reader"] == null ? _readerName : res["--reader"].ToString();

            _writerName = res["--writer"] == null ? _writerName : res["--writer"].ToString();

            if (res["--outputPath"] == null)
            {
                // do nothing, rely on default
            } 
            else if (res["--outputPath"].ToString() == String.Empty)
            {
                _outputPath = @".\";  // current working directory
            } 
            else
            {
                _outputPath = res["--outputPath"].ToString();
            }

            _metadataPath = res["<inputFile>"] == null ? _metadataPath : res["<inputFile>"].ToString();
        }
Ejemplo n.º 2
0
        public int Execute(string [] args)
        {
            TextReader input = Console.In;
            TextWriter output = Console.Out;
            var sc = new ServiceContainer();
            var rekoCfg = RekoConfigurationService.Load();
            sc.AddService<IConfigurationService>(rekoCfg);

            var docopt = new Docopt();
            IDictionary<string, ValueObject> options;
            try {
                options = docopt.Apply(usage, args);
            } catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return 1;
            }
            var arch = rekoCfg.GetArchitecture(options["-a"].ToString());
            if (arch == null)
            {
                Console.WriteLine(
                    "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.",
                    options["-a"]);
                return -1;
            }
            var envElem = rekoCfg.GetEnvironment(options["-e"].ToString());
            if (envElem == null)
            {
                Console.WriteLine(
                   "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.",
                   options["-e"]);
                return -1;
            }

            var platform = envElem.Load(sc, arch);
            try
            {
                input = new StreamReader(options["<inputfile>"].ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message);
                return 1;
            }

            if (options.ContainsKey("<outputfile>") &&  
                options["<outputfile>"] != null)
            {
                try
                {
                    output = new StreamWriter(options["<outputfile>"].ToString());
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message);
                    return 1;
                }
            }
            var xWriter = new XmlTextWriter(output)
            {
                Formatting = Formatting.Indented
            };

            XmlConverter c = new XmlConverter(input, xWriter, platform);
            c.Convert();
            output.Flush();
            return 0;
        }
Ejemplo n.º 3
0
        public static int Main(string[] args)
        {
            // call scanner and process all files with selected command
            var cmd_map = new Dictionary<string, Type>
            {
                {
                    "validate",
                    typeof(Validator)
                },
                {
                    "info",
                    typeof(Info)
                },
                {
                    "elfinfo",
                    typeof(ElfInfo)
                },
                {
                    "relocate",
                    typeof(Relocate)
                },
                {
                    "signatures",
                    typeof(SignatureGenerator)
                }
            };

            var docopt = new Docopt();
            var options = docopt.Apply(Program.options, args);
            var cmd = options["<command>"].Value.ToString();
            if (!cmd_map.ContainsKey(cmd))
            {
                Console.WriteLine("INVALID COMMAND:", cmd);
                Console.WriteLine("valid commands are:");
                foreach (var a in cmd_map)
                {
                    Console.WriteLine("  ", a);
                }
                return 1;
            }
            var cmd_cls = cmd_map[cmd];
            // execute command
            var cmdInst = (HunkCommand)Activator.CreateInstance(cmd_cls, options);
            cmdInst.Output = System.Console.Out;
            var res = cmdInst.run();
            return res ? 0 : 1;
        }