Esempio n. 1
0
        private async Task <string?> ChooseBackupPath(IUpgradeContext context, CancellationToken token)
        {
            var customPath = default(string);
            var commands   = new[]
            {
                UpgradeCommand.Create($"Use default path [{_backupPath}]"),
                UpgradeCommand.Create("Enter custom path", async(ctx, token) =>
                {
                    customPath = await _userInput.AskUserAsync("Please enter a custom path for backups:").ConfigureAwait(false);
                    return(!string.IsNullOrEmpty(customPath));
                })
            };

            while (!token.IsCancellationRequested)
            {
                var result = await _userInput.ChooseAsync("Please choose a backup path", commands, token).ConfigureAwait(false);

                if (await result.ExecuteAsync(context, token).ConfigureAwait(false))
                {
                    // customPath may be set in the lambda above.
#pragma warning disable CA1508 // Avoid dead conditional code
                    return(customPath ?? _backupPath);

#pragma warning restore CA1508 // Avoid dead conditional code
                }
            }

            return(null);
        }
Esempio n. 2
0
        private static UpgradeCommand UpgradeDb(IConsoleAdapter console, IErrorAdapter error, string connectionString)
        {
            var upgradeCommand = new UpgradeCommand()
            {
                ConnectionString = connectionString
            };

            upgradeCommand.Handle(console, error);
            return(upgradeCommand);
        }
Esempio n. 3
0
        public async Task <int> Execute(string[] args)
        {
            var rootCommand = new RootCommand("Party: A Virt-A-Mate package manager")
            {
                HelpCommand.CreateCommand(_renderer, _config, _controllerFactory),
                SearchCommand.CreateCommand(_renderer, _config, _controllerFactory),
                GetCommand.CreateCommand(_renderer, _config, _controllerFactory),
                ShowCommand.CreateCommand(_renderer, _config, _controllerFactory),
                StatusCommand.CreateCommand(_renderer, _config, _controllerFactory),
                UpgradeCommand.CreateCommand(_renderer, _config, _controllerFactory),
                PublishCommand.CreateCommand(_renderer, _config, _controllerFactory),
                CleanCommand.CreateCommand(_renderer, _config, _controllerFactory),
            };

            // For CoreRT:
            rootCommand.Name = Path.GetFileName(Environment.GetCommandLineArgs().FirstOrDefault()) ?? "party.exe";

            Exception exc    = null;
            var       parser = new CommandLineBuilder(rootCommand)
                               .UseVersionOption()
                               .UseHelp()
#if DEBUG
                               .UseParseDirective()
                               .UseDebugDirective()
#endif
                               .UseSuggestDirective()
                               // .RegisterWithDotnetSuggest()
                               .UseTypoCorrections()
                               .UseParseErrorReporting()
                               .UseExceptionHandler((e, ctx) => exc = e)
                               .CancelOnProcessTermination()
                               .Build();

            _renderer.WriteLine("Party, a Virt-A-Mate package manager, is still in it's early stages. Please file any issue or ideas at https://github.com/vam-community/vam-party/issues", ConsoleColor.Green);

            try
            {
                await parser.InvokeAsync(args, _renderer);
            }
            catch (Exception e)
            {
                exc = e;
            }

            if (exc != null)
            {
                return(HandleError(exc));
            }

            return(0);
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            ProgramExitCode exitCode = ProgramExitCode.Ok;

            Microsoft.Extensions.Logging.ILogger logger = null;

            if (args == null)
            {
                throw new ArgumentNullException(nameof(args), "Provide at least one command.");
            }

            try
            {
                switch (args[0])
                {
                case "upgrade":
                    logger = EnsureLoggerExists(logger);
                    UpgradeCommand upgradeCommand = new UpgradeCommand(logger);
                    upgradeCommand.Execute(args);
                    break;

                case "list":
                    ListCommand listCommand = new ListCommand(NullLogger.Instance);
                    listCommand.Execute(args);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("command", args[0], "Unknown command");
                }
            }
            catch (Exception e)
            {
                logger = EnsureLoggerExists(logger);
                logger.LogError(e.ToString());
                exitCode = ProgramExitCode.GeneralError;
            }

            return((int)exitCode);
        }
Esempio n. 5
0
 private async ValueTask <bool> ExecuteAndTimeCommand(IUpgradeContext context, UpgradeStep step, UpgradeCommand command, CancellationToken token)
 {
     using (_telemetry.TimeStep(command.Id, step))
     {
         return(await command.ExecuteAsync(context, token));
     }
 }