Ejemplo n.º 1
0
 public static CommandConfigurator RegisterFacebookOAuth2Provider(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(FacebookOAuth2Options.ClientId)
                                     .Description("OAuth2 ClientId for Facebook provider")
                                     .ConfigPath("OAuth2:Facebook:ClientId")
                                     .EnvironmentVariable("OAUTH2_FACEBOOK_CLIENT_ID")
                                     .Group(FacebookOAuth2Group)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(FacebookOAuth2Options.ClientSecret)
                                     .Description("OAuth2 ClientId for Facebook provider")
                                     .ConfigPath("OAuth2:Facebook:ClientSecret")
                                     .EnvironmentVariable("OAUTH2_FACEBOOK_CLIENT_SECRET")
                                     .Group(FacebookOAuth2Group)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(FacebookOAuth2Options.RedirectUri)
                                     .Description("OAuth2 redirect uri for Facebook provider")
                                     .ConfigPath("OAuth2:Facebook:RedirectUri")
                                     .EnvironmentVariable("OAUTH2_FACEBOOK_REDIRECT_URI")
                                     .Group(FacebookOAuth2Group)
                                     ));
 }
Ejemplo n.º 2
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(Text, "Text to show", "Default text to show")
     .SetExecute(Execute)
     .RegisterCommand("sub_show", "Show something", SubShowCommand.Configure);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Configure and get root command
        /// </summary>
        /// <param name="configureRootCommand">Action to configure command using CommandConfigurator</param>
        public Bootstrap Root(Action <CommandConfigurator> configureRootCommand)
        {
            var commandConfigurator = new CommandConfigurator("", "", CliConfig);

            configureRootCommand(commandConfigurator);

            return(new Bootstrap(CliConfig, commandConfigurator.GetCommandConfig()));
        }
Ejemplo n.º 4
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterOption(DownloadPodcastPath, "p", "The downloaded podcast saved path.", ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath)
     .RegisterOption(DownloadProgram, "dp", $"The downloaded program name, now support are {DownloadTools.Aria2Name} and {DownloadTools.IdmName}.", ProgramConfiguration.DownloadConfigurations.DownloadProgram)
     .RegisterOption(DownloadProgramPath, "dpp", $"The downloaded program path.", ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName)
     .SetExecute(Execute);
 }
Ejemplo n.º 5
0
        public void ApplyTo(HostConfigurator configurator)
        {
            if (configurator == null)
                throw new ArgumentNullException("configurator");

            var commandConfigurator = new CommandConfigurator(_command);

            configurator.AddConfigurator(commandConfigurator);
        }
Ejemplo n.º 6
0
    public ICommandConfigurator AddCommand <TCommand>(string name)
        where TCommand : class, ICommandLimiter <TSettings>
    {
        var command      = ConfiguredCommand.FromType <TCommand>(name);
        var configurator = new CommandConfigurator(command);

        _command.Children.Add(command);
        return(configurator);
    }
Ejemplo n.º 7
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterFlag(b => b.Name(Verbose).Abr("v").Description("Verbose description").DefaultValue(false))
     .RegisterFlag(b => b.Name(Clear).Description("Clear description").DefaultValue(false))
     .RegisterOption <string>(b => b.Name(Option1).Abr("o1").Description("Option 1 description").DefaultValue("default"))
     .RegisterOption <string>(b => b.Name(Option2).Description("Option 2 description").DefaultValue("default2"))
     .RegisterParameter <string>(b => b.Name(Param1).Description("Parameter 1 description").DefaultValue("."))
     .SetExecute(Execute);
 }
Ejemplo n.º 8
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(Date, "Release will be downloaded after the date.", "20210101")
     .RegisterFlag(SimpleFile, "s", "Create a simple file just have download url, could use to other download software. And not automatic download.", false)
     .RegisterOption(DownloadDirectory, "d", "Download file directory.", ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath)
     .RegisterCommand(DownloadListCommand.Name, DownloadListCommand.Description, DownloadListCommand.Configure)
     .RegisterCommand(DownloadSelectCommand.Name, DownloadSelectCommand.Description, DownloadSelectCommand.Configure)
     .SetExecute(Execute);
 }
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(PodcastName, "Specific a podcast and show all releases", "None")
     .RegisterParameter <int[]>(b => b
                                .Name(SelectIndex)
                                .Description("select index of podcast release")
                                .Converter(new ArrayInt32Converter()))
     .SetExecute(Execute);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Configure and get root command
        /// </summary>
        /// <param name="cli">NFlags Cli instance</param>
        /// <param name="configureRootCommand">Action to configure command using CommandConfigurator</param>
        public static Bootstrap Root <TArguments>(this Cli cli, Action <CommandConfigurator <TArguments> > configureRootCommand)
        {
            var commandConfigurator = new CommandConfigurator <TArguments>(
                new CommandConfigurator("", "", cli.CliConfig)
                );

            configureRootCommand(commandConfigurator);

            return(new Bootstrap(cli.CliConfig, commandConfigurator.GetCommandConfig()));
        }
Ejemplo n.º 11
0
 public static CommandConfigurator RegisterErrorHandling(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterFlag(b => b
                          .Name(ErrorHandlingOptions.ShowCallStack)
                          .Description("Enables call stack printing when handling errors.")
                          .ConfigPath("ErrorHandling:ShowCallStack")
                          .EnvironmentVariable("DEVELOPMENT_SHOW_CALL_STACK")
                          .Group(ErrorHandlingGroup)
                          ));
 }
Ejemplo n.º 12
0
 public static CommandConfigurator RegisterTokenWrite(this CommandConfigurator commandConfigurator, string tokenName)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(tokenName.ToLower() + AuthOptions.TokenPrivateKeySuffix)
                                     .Description($"Private key used to generate {tokenName.ToLower()} token")
                                     .ConfigPath($"Auth:{tokenName}Token:PrivateKey")
                                     .EnvironmentVariable($"{tokenName.ToUpper()}_TOKEN_PRIVATE_KEY")
                                     .Group(AuthorizationGroup)
                                     ));
 }
Ejemplo n.º 13
0
        public void ApplyTo(HostConfigurator configurator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var commandConfigurator = new CommandConfigurator(_command);

            configurator.AddConfigurator(commandConfigurator);
        }
Ejemplo n.º 14
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterFlag(Verbose, "v", "Verbose description", false)
     .RegisterFlag(Clear, "Clear description", false)
     .RegisterOption(Option1, "o1", "Option 1 description", "default")
     .RegisterOption(Option2, "Option 2 description", "default2")
     .RegisterParameter(Param1, "Parameter 1 description", ".")
     .SetExecute(Execute)
     .RegisterCommand(ShowCommand.Name, ShowCommand.Description, ShowCommand.Configure)
     .RegisterCommand(ListCommand.Name, "List something", ListCommand.Configure);
 }
Ejemplo n.º 15
0
 public static CommandConfigurator RegisterDefaultServiceCommand <TStartup>(
     this CommandConfigurator configurator,
     string commandName,
     string commandDescription,
     IGenericConfig configuration,
     Action <CommandConfigurator, IGenericConfig> additionalConfiguration = null) where TStartup : class
 {
     return(configurator.RegisterDefaultCommand(
                commandName,
                commandDescription,
                c => c.ConfigureService <TStartup>(configuration, additionalConfiguration)
                ));
 }
Ejemplo n.º 16
0
 public static CommandConfigurator RegisterAuth(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterFlag(b => b
                          .Name(AuthOptions.DisableAuth)
                          .Description("Disables auth")
                          .ConfigPath("Auth:DisableAuth")
                          .EnvironmentVariable("DEVELOPMENT_DISABLE_AUTH")
                          .Group(AuthorizationGroup)
                          )
            .RegisterToken(AuthOptions.AccessTokenName)
            .RegisterToken(AuthOptions.RefreshTokenName));
 }
Ejemplo n.º 17
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .PrintHelpOnExecute()
     .SetExecute(Execute)
     .RegisterCommand(AddCommand.Name, AddCommand.Description, AddCommand.Configure)
     .RegisterCommand(RemoveCommand.Name, RemoveCommand.Description, RemoveCommand.Configure)
     .RegisterCommand(ShowCommand.Name, ShowCommand.Description, ShowCommand.Configure)
     .RegisterCommand(ListCommand.Name, ListCommand.Description, ListCommand.Configure)
     .RegisterCommand(UpdateCommand.Name, UpdateCommand.Description, UpdateCommand.Configure)
     .RegisterCommand(UpgradeCommand.Name, UpgradeCommand.Description, UpgradeCommand.Configure)
     .RegisterCommand(DownloadCommand.Name, DownloadCommand.Description, DownloadCommand.Configure)
     .RegisterCommand(AutoMetadataCommand.Name, AutoMetadataCommand.Description, AutoMetadataCommand.Configure)
     .RegisterCommand(ConfigCommand.Name, ConfigCommand.Description, ConfigCommand.Configure);
 }
Ejemplo n.º 18
0
 public static CommandConfigurator RegisterConsulServiceDiscovery(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterFlag(b => b
                          .Name(ConsulFlags.Enabled)
                          .Description("True, if service should be registered in Consul service discovery")
                          .ConfigPath("Consul:Enabled")
                          .EnvironmentVariable("CONSUL_ENABLED")
                          .DefaultValue(false)
                          .Group(ConsulGroup)
                          )
            .RegisterOption <string>(b => b
                                     .Name(ConsulOptions.ConsulAddress)
                                     .Description("Address of consul cluster")
                                     .ConfigPath("Consul:Address")
                                     .EnvironmentVariable("CONSUL_ADDRESS")
                                     .Group(ConsulGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(ConsulOptions.ServiceId)
                                     .Description("Service id for Consul service discovery")
                                     .ConfigPath("Consul:Service:Id")
                                     .EnvironmentVariable("CONSUL_SERVICE_ID")
                                     .Group(ConsulGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(ConsulOptions.ServiceName)
                                     .Description("Service name for Consul service discovery")
                                     .ConfigPath("Consul:Service:Name")
                                     .EnvironmentVariable("CONSUL_SERVICE_NAME")
                                     .Group(ConsulGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(ConsulOptions.ServiceUri)
                                     .Description("Service Uri for Consul service discovery")
                                     .ConfigPath("Consul:Service:Uri")
                                     .EnvironmentVariable("CONSUL_SERVICE_URI")
                                     .Group(ConsulGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(ConsulOptions.ServiceTags)
                                     .Description("Service Tags for Consul service discovery (separated by comma)")
                                     .ConfigPath("Consul:Service:Tags")
                                     .EnvironmentVariable("CONSUL_SERVICE_TAGS")
                                     .Group(ConsulGroup)
                                     ));
 }
Ejemplo n.º 19
0
 public static CommandConfigurator RegisterTokenRead(this CommandConfigurator commandConfigurator, string tokenName)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(tokenName.ToLower() + AuthOptions.TokenPublicKeySuffix)
                                     .Description($"Public key used to decode {tokenName.ToLower()} token")
                                     .ConfigPath($"Auth:{tokenName}Token:PublicKey")
                                     .EnvironmentVariable($"{tokenName.ToUpper()}_TOKEN_PUBLIC_KEY")
                                     .Group(AuthorizationGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(tokenName.ToLower() + AuthOptions.TokenSecretSuffix)
                                     .Description($"Secret for {tokenName.ToLower()} token keys")
                                     .ConfigPath($"Auth:{tokenName}Token:Secret")
                                     .EnvironmentVariable($"{tokenName.ToUpper()}_TOKEN_SECRET")
                                     .Group(AuthorizationGroup)
                                     ));
 }
Ejemplo n.º 20
0
 public static CommandConfigurator RegisterKafka(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(KafkaOptions.GroupId)
                                     .Description("Protocol string to use when connecting to MongoDb")
                                     .ConfigPath("Kafka:GroupId")
                                     .EnvironmentVariable("KAFKA_GROUP_ID")
                                     .Group(KafkaGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(KafkaOptions.BootstrapServers)
                                     .Description("Kafka bootstrap servers")
                                     .ConfigPath("Kafka:BootstrapServers")
                                     .EnvironmentVariable("KAFKA_BOOTSTRAP_SERVERS")
                                     .Group(KafkaGroup)
                                     ));
 }
Ejemplo n.º 21
0
 public static CommandConfigurator RegisterPrometheusMetrics(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterFlag(b => b
                          .Name(PrometheusFlags.Enabled)
                          .Description("True, if service should provide metrics for Prometheus")
                          .ConfigPath("Prometheus:Enabled")
                          .EnvironmentVariable("CONSUL_ENABLED")
                          .DefaultValue(false)
                          .Group(PrometheusGroup)
                          )
            .RegisterOption <string>(b => b
                                     .Name(PrometheusOptions.Path)
                                     .Description("Path of metrics endpoint")
                                     .ConfigPath("Prometheus:Uri")
                                     .EnvironmentVariable("PROMETHEUS_PATH")
                                     .DefaultValue("/metrics")
                                     .Group(PrometheusGroup)
                                     ));
 }
Ejemplo n.º 22
0
 public static CommandConfigurator RegisterMongoDb(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(MongoDbOptions.Protocol)
                                     .Description("Protocol string to use when connecting to MongoDb")
                                     .ConfigPath("MongoDB:Protocol")
                                     .EnvironmentVariable("MONGODB_PROTOCOL")
                                     .DefaultValue("mongodb")
                                     .Group(MongoDbGroup)
                                     )
            .RegisterOption <string[]>(b => b
                                       .Name(MongoDbOptions.Hosts)
                                       .Description("MongoDb host. Can be set multiple times for multiple hosts. When using Environment Variable separate values with comma.")
                                       .ConfigPath("MongoDB:Hosts")
                                       .EnvironmentVariable("MONGODB_HOSTS")
                                       .Group(MongoDbGroup)
                                       )
            .RegisterOption <string>(b => b
                                     .Name(MongoDbOptions.Username)
                                     .Description("MongoDb username")
                                     .ConfigPath("MongoDB:Username")
                                     .EnvironmentVariable("MONGODB_USERNAME")
                                     .Group(MongoDbGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(MongoDbOptions.Password)
                                     .Description("MongoDb password")
                                     .ConfigPath("MongoDB:Password")
                                     .EnvironmentVariable("MONGODB_PASSWORD")
                                     .Group(MongoDbGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(MongoDbOptions.Options)
                                     .Description("MongoDb connection options in format 'option=value,option2=value'")
                                     .ConfigPath("MongoDB:Options")
                                     .EnvironmentVariable("MONGODB_OPTIONS")
                                     .Group(MongoDbGroup)
                                     ));
 }
Ejemplo n.º 23
0
 public static CommandConfigurator RegisterRabbitMq(this CommandConfigurator commandConfigurator)
 {
     return(commandConfigurator
            .RegisterOption <string>(b => b
                                     .Name(RabbitMqOptions.HostName)
                                     .Description("RabbitMQ Host name")
                                     .ConfigPath("RabbitMQ:Hostname")
                                     .EnvironmentVariable("RABBITMQ_HOSTNAME")
                                     .Group(RabbitMqGroup)
                                     )
            .RegisterOption <int>(b => b
                                  .Name(RabbitMqOptions.Port)
                                  .Description("RabbitMQ port")
                                  .ConfigPath("RabbitMQ:Port")
                                  .EnvironmentVariable("RABBITMQ_PORT")
                                  .Group(RabbitMqGroup)
                                  )
            .RegisterOption <string>(b => b
                                     .Name(RabbitMqOptions.UserName)
                                     .Description("RabbitMQ username")
                                     .ConfigPath("RabbitMQ:UserName")
                                     .EnvironmentVariable("RABBITMQ_USERNAME")
                                     .Group(RabbitMqGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(RabbitMqOptions.Password)
                                     .Description("RabbitMQ password")
                                     .ConfigPath("RabbitMQ:Password")
                                     .EnvironmentVariable("RABBITMQ_PASSWORD")
                                     .Group(RabbitMqGroup)
                                     )
            .RegisterOption <string>(b => b
                                     .Name(RabbitMqOptions.VirtualHost)
                                     .Description("RabbitMQ virtual host")
                                     .ConfigPath("RabbitMQ:VirtualHost")
                                     .EnvironmentVariable("RABBITMQ_VIRTUALHOST")
                                     .Group(RabbitMqGroup)
                                     ));
 }
Ejemplo n.º 24
0
        private static CommandConfigurator ConfigureService <TStartup>(
            this CommandConfigurator configurator,
            IGenericConfig configuration,
            Action <CommandConfigurator, IGenericConfig> additionalConfiguration = null) where TStartup : class
        {
            configurator.RegisterOption <int>(b => b
                                              .Name(ServiceOptions.Port)
                                              .Abr("p")
                                              .Description("Listening port")
                                              .EnvironmentVariable("PORT")
                                              .DefaultValue(5000)
                                              )
            .RegisterErrorHandling()
            .SetExecute((commandArgs, output) =>
            {
                RunKestrelHost <TStartup>(commandArgs, configuration, output);
            });

            additionalConfiguration?.Invoke(configurator, configuration);

            return(configurator);
        }
Ejemplo n.º 25
0
 public static CommandConfigurator RegisterOptions(this CommandConfigurator c)
 {
     return(c.RegisterOption <int>(b => b
                                   .Name(Port)
                                   .Abr("p")
                                   .Description("Listening port")
                                   .EnvironmentVariable("PORT")
                                   .ConfigPath("Server:Port")
                                   .DefaultValue(5000)
                                   )
            .RegisterOption <int>(b => b
                                  .Name(MaxConcurrentConnections)
                                  .Description("Maximum number of open connections")
                                  .ConfigPath("Server:MaxConcurrentConnections")
                                  .DefaultValue(5000)
                                  )
            .RegisterOption <string>(b => b
                                     .Name(Greeting)
                                     .Description("Greeting message.")
                                     .ConfigPath("Greeting")
                                     .DefaultValue("Hello World!")
                                     ));
 }
Ejemplo n.º 26
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(PodcastName, "The name of podcast need to remove.", "Name is not found.")
     .SetExecute(Execute);
 }
Ejemplo n.º 27
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(PodcastName, "Podcast information to show", "Podcast name is not found.")
     .SetExecute(Execute);
 }
Ejemplo n.º 28
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(PodcastName, "Specific a podcast and show all releases", "None")
     .SetExecute(Execute);
 }
Ejemplo n.º 29
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(PodcastUrl, "The url of podcast.", "Url is not found.")
     .SetExecute(Execute);
 }
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .SetExecute(Execute);
 }
Ejemplo n.º 31
0
 public static void Configure(CommandConfigurator configurator)
 {
     configurator
     .RegisterParameter(Text, "Text to show", "Default text to show")
     .SetExecute(Execute);
 }