internal static void Register(CommandLineApplication app,
                                      Func <ILogger> getLogger)
        {
            app.Command("list", ListCmd =>
            {
                ListCmd.Command("source", SourceCmd =>
                {
                    CommandOption format = SourceCmd.Option(
                        "--format",
                        Strings.SourcesCommandFormatDescription,
                        CommandOptionType.SingleValue);
                    CommandOption configfile = SourceCmd.Option(
                        "--configfile",
                        Strings.Option_ConfigFile,
                        CommandOptionType.SingleValue);
                    SourceCmd.HelpOption("-h|--help");
                    SourceCmd.Description = Strings.ListSourceCommandDescription;
                    SourceCmd.OnExecute(() =>
                    {
                        var args = new ListSourceArgs()
                        {
                            Format     = format.Value(),
                            Configfile = configfile.Value(),
                        };

                        ListSourceRunner.Run(args, getLogger);
                        return(0);
                    });
                });
                ListCmd.Command("client-cert", ClientCertCmd =>
                {
                    CommandOption configfile = ClientCertCmd.Option(
                        "--configfile",
                        Strings.Option_ConfigFile,
                        CommandOptionType.SingleValue);
                    ClientCertCmd.HelpOption("-h|--help");
                    ClientCertCmd.Description = Strings.ListClientCertCommandDescription;
                    ClientCertCmd.OnExecute(() =>
                    {
                        var args = new ListClientCertArgs()
                        {
                            Configfile = configfile.Value(),
                        };

                        ListClientCertRunner.Run(args, getLogger);
                        return(0);
                    });
                });
                ListCmd.HelpOption("-h|--help");
                ListCmd.Description = Strings.List_Description;
                ListCmd.OnExecute(() =>
                {
                    app.ShowHelp("list");
                    return(0);
                });
            });
        }
示例#2
0
        public override void ExecuteCommand()
        {
            if (SourceProvider == null)
            {
                throw new InvalidOperationException(LocalizedResourceManager.GetString("Error_SourceProviderIsNull"));
            }

            SourcesAction action    = SourcesAction.None;
            var           actionArg = Arguments.FirstOrDefault();

            if (string.IsNullOrEmpty(actionArg))
            {
                action = SourcesAction.List;
            }
            else
            {
                if (!Enum.TryParse <SourcesAction>(actionArg, ignoreCase: true, out action))
                {
                    Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUsageSummary"));
                }
            }

            switch (action)
            {
            case SourcesAction.Add:
                var addArgs = new AddSourceArgs()
                {
                    Name = Name, Source = Source, Username = Username, Password = Password, StorePasswordInClearText = StorePasswordInClearText, ValidAuthenticationTypes = ValidAuthenticationTypes, Configfile = ConfigFile
                };
                AddSourceRunner.Run(addArgs, () => Console);
                break;

            case SourcesAction.Update:
                var updateSourceArgs = new UpdateSourceArgs()
                {
                    Name = Name, Source = Source, Username = Username, Password = Password, StorePasswordInClearText = StorePasswordInClearText, ValidAuthenticationTypes = ValidAuthenticationTypes, Configfile = ConfigFile
                };
                UpdateSourceRunner.Run(updateSourceArgs, () => Console);
                break;

            case SourcesAction.Remove:
                var removeSourceArgs = new RemoveSourceArgs()
                {
                    Name = Name, Configfile = ConfigFile
                };
                RemoveSourceRunner.Run(removeSourceArgs, () => Console);
                break;

            case SourcesAction.Disable:
                var disableSourceArgs = new DisableSourceArgs()
                {
                    Name = Name, Configfile = ConfigFile
                };
                DisableSourceRunner.Run(disableSourceArgs, () => Console);
                break;

            case SourcesAction.Enable:
                var enableSourceArgs = new EnableSourceArgs()
                {
                    Name = Name, Configfile = ConfigFile
                };
                EnableSourceRunner.Run(enableSourceArgs, () => Console);
                break;

            case SourcesAction.List:
                var listSourceArgs = new ListSourceArgs()
                {
                    Configfile = ConfigFile, Format = Format.ToString()
                };
                ListSourceRunner.Run(listSourceArgs, () => Console);
                break;
            }
        }