예제 #1
0
        static int RunInteractive(InteractiveOptions opts)
        {
            using (var client = new ModbusRtuClient())
            {
                client.PortName = opts.PortName;
                client.BaudRate = opts.BaudRate;
                client.DataBits = opts.DataBits;
                client.Parity   = opts.Parity;

                if (!OpenPort(client))
                {
                    return(1);
                }

                var  parser = new InteractiveCommandParser(client);
                bool close  = false;
                do
                {
                    Console.Error.Write("] ");
                    var line = Console.In.ReadLine();
                    try
                    {
                        close = parser.ProcessCommand(line);
                    }
                    catch (Exception exp)
                    {
                        HandleException(exp);
                    }
                    Console.Out.WriteLine();
                }while (!close);
            }
            return(0);
        }
예제 #2
0
        private static void PromptForPackage(string volume, InteractiveOptions options)
        {
            Console.WriteLine();
            var packages = ListPackages(volume);

            Console.WriteLine("↑/↓ change selection | ←/→ page | ⏎ confirm".Pastel(Color.Gray));
            var package = Prompt.Select("Choose a package to remove", packages,
                                        5);

            if (package.StartsWith("com.apple.", StringComparison.OrdinalIgnoreCase))
            {
                if (!options.IsForced)
                {
                    Console.WriteLine(
                        "You cannot remove Apple-provided packages without 'force' flag.".Pastel(Color.OrangeRed));
                    return;
                }

                Console.WriteLine("Double check that you want to remove an Apple-provided package.");
                Console.WriteLine("This package may be required by macOS.");
                if (!Prompt.Confirm("Continue?"))
                {
                    return;
                }
            }

            if (RemovePackage(package, true, false))
            {
                Console.WriteLine($"Package '{package}' was removed!".Pastel(Color.Green));
            }
            else
            {
                Console.WriteLine($"Package '{package}' was not removed!".Pastel(Color.OrangeRed));
            }
        }
예제 #3
0
        private static int GenerateTokenInteractivelyAndExit(InteractiveOptions options)
        {
            InteractiveUserTokenGenerator generator = new InteractiveUserTokenGenerator();
            var authResult = generator.GenerateToken(options).GetAwaiter().GetResult();

            return(ExitWithResult(authResult.AccessToken));
        }
예제 #4
0
        private static void RunInteractively(InteractiveOptions options)
        {
            if (getuid() != 0 && geteuid() != 0)
            {
                Console.WriteLine("Interactive mode must be started as root.".Pastel(Color.OrangeRed));
                return;
            }

            var volumes = GetVolumes();
            var volume  = PromptForVolume(volumes);

            var shouldContinue = true;

            while (shouldContinue)
            {
                PromptForPackage(volume, options);

                Console.WriteLine();
                var nextStep = Prompt.Select("What would you like to do next",
                                             new[]
                {
                    "1. Change volume to operate on.",
                    "2. Remove another package.",
                    "3. Exit"
                });
                switch (nextStep[0])
                {
                case '1':
                {
                    volume = PromptForVolume(volumes);
                    break;
                }

                case '2':
                {
                    continue;
                }

                case '3':
                {
                    shouldContinue = false;
                    break;
                }
                }
            }
        }
예제 #5
0
        static int Startup(Options options)
        {
            var localOptions = options.Interactive
                ? InteractiveOptions.Prompt(options)
                : options;

            if (localOptions == null)
            {
                return(0);
            }

            string[] arguments =
            {
                $"-target={localOptions.Target}",
                $"-configuration={localOptions.Configuration}",
                $"-environment={localOptions.Environment}",
                $"-verbosity={localOptions.Verbosity}",
                $"-publishDirectory={localOptions.PublishDirectory}"
            };

            var returnCode = new CakeHostBuilder()
                             .WithArguments(arguments)
                             .UseStartup <FrostingStartup>()
                             .Build()
                             .Run();

            // If interactive, keep asking
            if (options.Interactive)
            {
                Console.WriteLine();
                return(Startup(options));
            }

#if DEBUG
            // Otherwise, wait for key press if debugger is attached
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.WriteLine();
                Console.WriteLine("Press any key to quit...");
                Console.ReadKey();
            }
#endif

            return(returnCode);
        }
예제 #6
0
        private static int InteractiveSync(InteractiveOptions opts)
        {
            // Interactive mode
            Console.WriteLine("--- WARNING ---");
            Console.WriteLine("Local databases for the selected profile will be overwritten! Ctrl+C out NOW if you'd like to keep them!");
            Console.WriteLine();

            Console.WriteLine("Select project profile to run:");
            var i = 1;

            var profiles = ProjectProfile.List().ToList();

            foreach (var p in profiles)
            {
                Console.WriteLine($"[{i++}] {p.Name}");
            }

            Console.WriteLine($"[{i}] Exit");

            var k = Console.ReadKey();

            if (!int.TryParse(k.KeyChar.ToString(), out var selectedIdx))
            {
                return(0);
            }

            if (profiles.Count < selectedIdx)
            {
                return(0);
            }

            var selectedProfile = profiles[selectedIdx - 1];

            DatabaseToDatabaseSync(new Db2dbOptions
            {
                InputConnectionString  = selectedProfile.FromConnectionString,
                OutputConnectionString = selectedProfile.ToConnectionString,
                Databases        = selectedProfile.DatabasesToSync,
                WorkingDirectory = selectedProfile.WorkingDirectory,
                LocalUser        = selectedProfile.LocalDbUser
            });

            return(0);
        }