Exemplo n.º 1
0
Arquivo: Program.cs Projeto: 602p/nbfc
        private static void ParseArgs(string[] args)
        {
            var opt     = new Verbs();
            var helpGen = new HelpGenerator <Verbs>();

            helpGen.DescriptionDistance = 25;
            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, helpGen);

            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService(opt.Start.ReadOnly);
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
            else
            {
                Console.WriteLine(helpGen.GetHelp(parser.Config));
            }
        }
Exemplo n.º 2
0
Arquivo: Program.cs Projeto: qzcw/nbfc
        private static void ParseArgs(string[] args)
        {
            var opt = new Verbs();
            var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator());
            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService();
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
        }
Exemplo n.º 3
0
        private static void ParseArgs(string[] args)
        {
            var opt    = new Verbs();
            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator());

            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService();
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
        }
Exemplo n.º 4
0
        private static void ParseArgs(string[] args)
        {
            var opt     = new Verbs();
            var helpGen = new NbfcCli.CommandLineOptions.HelpGenerator <Verbs>();

            helpGen.DescriptionDistance = 29;
            helpGen.GenericDescription  = "All input values are interpreted as decimal numbers by default."
                                          + Environment.NewLine
                                          + "Hexadecimal values may be entered by prefixing them with \"0x\".";

            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, helpGen);

            parser.StrictParse(args);

            if (opt.ECDump != null)
            {
                ECDump();
            }
            else if (opt.ECRead != null)
            {
                ECRead(opt.ECRead.Register);
            }
            else if (opt.ECWrite != null)
            {
                ECWrite(opt.ECWrite.Register, opt.ECWrite.Value, opt.ECWrite.Verbose);
            }
            else if (opt.ECMonitor != null)
            {
                if (opt.ECMonitor.Interval < 1)
                {
                    Console.Error.WriteLine("The interval must be at least 1 second");
                    return;
                }

                if ((opt.ECMonitor.Timespan < 2 * opt.ECMonitor.Interval) && (opt.ECMonitor.Timespan > 0))
                {
                    Console.Error.WriteLine("The monitored timespan must be at least (2 * interval)");
                    return;
                }

                ECMonitor(
                    opt.ECMonitor.Timespan,
                    opt.ECMonitor.Interval,
                    opt.ECMonitor.ReportPath,
                    opt.ECMonitor.Clearly,
                    opt.ECMonitor.Decimal);
            }
            else
            {
                Console.WriteLine(helpGen.GetHelp(parser.Config));
            }
        }
Exemplo n.º 5
0
        static void Attribute(string[] args)
        {
            var opt = CliParser.StrictParse <Options>(args);

            //var opt = CliParser.Parse<Options>(
            //    "-vvv output.txt 1 2 -1 7".Split());
            Console.WriteLine(opt.Verbosity);
            // >>> 3

            Console.WriteLine(opt.OutputFile);
            // >>> output.txt

            var sum = 0;

            foreach (var number in opt.Numbers)
            {
                sum += number;
            }
            Console.WriteLine(sum);
            // >>> 9
        }
Exemplo n.º 6
0
        private static Options Configure(string[] args)
        {
            var options = CliParser.StrictParse <Options>(args);
            var parser  = new CliParser <Options>(options);
            var help    = new AutomaticHelpGenerator <Options>();

            var usage = help.GetUsage(parser.Config);

            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine(usage);
            Console.ResetColor();
            Console.WriteLine();

            var current = help.GetValues(options);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(current);
            Console.ResetColor();
            Console.WriteLine();

            return(options);
        }
        static void Main(string[] args)
        {
            var container = new LightInject.ServiceContainer();

            container.Register <ApplicationInformation>(c => new ApplicationInformation("ShinyMusicSynchronizer", 1, 0), new PerContainerLifetime());
            container.Register <PortableDeviceCollection>(c => CreatePortableDeviceCollectionFromApplicationInformation(c.GetInstance <ApplicationInformation>()));

            container.Register <IUserInterface, ConsoleUserInterface>(new PerContainerLifetime());
            container.Register <Action <ICommandMessage> >(c => new Action <ICommandMessage>(c.GetInstance <IUserInterface>().ReportMessage));

            container.Register <Options>(c => CliParser.StrictParse <Options>(args), new PerContainerLifetime());
            container.Register <OptionsToCommandParser, OptionsToCommandParser>();
            container.Register <ListDevicesCommand.Options>(c => c.GetInstance <Options>().ListDevices);
            container.Register <ListDevicesCommand, ListDevicesCommand>();
            container.Register <SynchronizeCommand.Options>(c => c.GetInstance <Options>().Synchronize);
            container.Register <SynchronizeCommand, SynchronizeCommand>();
            container.Register <ICommand>(c => c.GetInstance <OptionsToCommandParser>().CreateCommandFromOptions());

            var command = container.GetInstance <ICommand>();

            command.Execute();
        }
Exemplo n.º 8
0
        private static void ParseArgs(string[] args)
        {
            var opt = new Verbs();
            var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new CustomHelpGenerator());
            parser.StrictParse(args);

            if (opt.ECDump != null)
            {
                ECDump();
            }
            else if (opt.ECRead != null)
            {
                ECRead(opt.ECRead.Register);
            }
            else if (opt.ECWrite != null)
            {
                ECWrite(opt.ECWrite.Register, opt.ECWrite.Value, opt.ECWrite.Verbose);
            }
            else
            {
                Console.WriteLine((new CustomHelpGenerator()).GetHelp(null));
            }
        }
Exemplo n.º 9
0
        private static void ParseArgs(string[] args)
        {
            var opt    = new Verbs();
            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, new CustomHelpGenerator());

            parser.StrictParse(args);

            if (opt.ECDump != null)
            {
                ECDump();
            }
            else if (opt.ECRead != null)
            {
                ECRead(opt.ECRead.Register);
            }
            else if (opt.ECWrite != null)
            {
                ECWrite(opt.ECWrite.Register, opt.ECWrite.Value, opt.ECWrite.Verbose);
            }
            else
            {
                Console.WriteLine((new CustomHelpGenerator()).GetHelp(null));
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var opt       = CliParser.StrictParse <Options>(args);
            var stopwatch = new Stopwatch();

            XDocument leftDoc  = null;
            XDocument rightDoc = null;

            if (opt.Verbose)
            {
                Console.WriteLine("Loading \"{0}\"...", opt.LeftFile);
            }
            leftDoc = XDocument.Load(opt.LeftFile);
            if (opt.Verbose)
            {
                Console.WriteLine("Loading \"{0}\"...", opt.RightFile);
            }
            rightDoc = XDocument.Load(opt.RightFile);
            if (opt.Verbose)
            {
                Console.WriteLine("Comparing differences...");
            }
            stopwatch.Start();

            var comparer = new XmlComparer();
            var diff     = comparer.Compare(leftDoc.Root, rightDoc.Root);

            if (!diff.IsChanged && opt.Verbose)
            {
                Console.WriteLine("No changes detected!");
            }

            if (opt.Verbose)
            {
                Console.WriteLine("Compared in {0} ms.", stopwatch.ElapsedMilliseconds);
            }

            if (!string.IsNullOrEmpty(opt.OutputHtmlFile))
            {
                if (opt.Verbose)
                {
                    Console.WriteLine("Creating HTML output...");
                    stopwatch.Restart();
                }

                var visitor = new HtmlVisitor();
                visitor.Visit(diff);

                if (opt.Verbose)
                {
                    Console.WriteLine("Writing HTML output to \"{0}\"...", opt.OutputHtmlFile);
                }
                File.WriteAllText(opt.OutputHtmlFile, visitor.Result);

                if (opt.Verbose)
                {
                    Console.WriteLine("HTML output file created in {0} ms.", stopwatch.ElapsedMilliseconds);
                }
            }

            if (!string.IsNullOrEmpty(opt.OutputXdtFile))
            {
                if (opt.Verbose)
                {
                    Console.WriteLine("Creating XDT output...");
                    stopwatch.Restart();
                }

                var visitor = new XdtVisitor();
                visitor.Visit(diff);

                if (opt.Verbose)
                {
                    Console.WriteLine("Writing XDT output to \"{0}\"...", opt.OutputXdtFile);
                }
                File.WriteAllText(opt.OutputXdtFile, visitor.Result);

                if (opt.Verbose)
                {
                    Console.WriteLine("XDT output file created in {0} ms.", stopwatch.ElapsedMilliseconds);
                }
            }
            stopwatch.Stop();

            if (opt.Verbose)
            {
                Console.WriteLine("\nShowing text diff:");
            }
            if (opt.Verbose || (string.IsNullOrEmpty(opt.OutputHtmlFile) && string.IsNullOrEmpty(opt.OutputXdtFile)))
            {
                var vistor = new ToStringVisitor();
                vistor.Visit(diff);
                Console.WriteLine(vistor.Result);
            }
        }