2020-06-01 15:22:41 +02:00
using System ;
using CommandLine ;
2018-05-02 20:19:11 +02:00
namespace Geekbot.net.Lib
{
public class RunParameters
{
2018-05-13 18:47:01 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* General *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2020-06-01 15:22:41 +02:00
[Option("token", HelpText = "Set a new bot token. By default it will use your previous bot token which was stored in the database (default: null) (env: TOKEN)")]
public string Token { get ; set ; } = ParamFallback ( "TOKEN" ) ;
2018-05-02 20:19:11 +02:00
2020-06-01 15:22:41 +02:00
[Option('V', "verbose", HelpText = "Logs everything. (default: false) (env: LOG_VERBOSE)")]
public bool Verbose { get ; set ; } = ParamFallback ( "LOG_VERBOSE" , false ) ;
2018-05-02 20:19:11 +02:00
2020-06-01 15:22:41 +02:00
[Option('j', "log-json", HelpText = "Logger outputs json (default: false ) (env: LOG_JSON)")]
public bool LogJson { get ; set ; } = ParamFallback ( "LOG_JSON" , false ) ;
[Option('e', "expose-errors", HelpText = "Shows internal errors in the chat (default: false) (env: EXPOSE_ERRORS)")]
public bool ExposeErrors { get ; set ; } = ParamFallback ( "EXPOSE_ERRORS" , false ) ;
2018-05-02 20:19:11 +02:00
2018-05-13 18:47:01 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Database *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2020-06-01 15:22:41 +02:00
[Option("in-memory", HelpText = "Uses the in-memory database instead of postgresql (default: false) (env: DB_INMEMORY)")]
public bool InMemory { get ; set ; } = ParamFallback ( "DB_INMEMORY" , false ) ;
2018-05-10 00:00:51 +02:00
// Postresql connection
2020-06-01 15:22:41 +02:00
[Option("database", HelpText = "Select a postgresql database (default: geekbot) (env: DB_DATABASE)")]
public string DbDatabase { get ; set ; } = ParamFallback ( "DB_DATABASE" , "geekbot" ) ;
2018-05-10 00:00:51 +02:00
2020-06-01 15:22:41 +02:00
[Option("db-host", HelpText = "Set a postgresql host (default: localhost) (env: DB_HOST)")]
public string DbHost { get ; set ; } = ParamFallback ( "DB_HOST" , "localhost" ) ;
2018-05-10 00:00:51 +02:00
2020-06-01 15:22:41 +02:00
[Option("db-port", HelpText = "Set a postgresql host (default: 5432) (env: DB_PORT)")]
public string DbPort { get ; set ; } = ParamFallback ( "DB_PORT" , "5432" ) ;
2018-05-10 00:00:51 +02:00
2020-06-01 15:22:41 +02:00
[Option("db-user", HelpText = "Set a postgresql user (default: geekbot) (env: DB_USER)")]
public string DbUser { get ; set ; } = ParamFallback ( "DB_USER" , "geekbot" ) ;
2018-05-10 00:00:51 +02:00
2020-06-01 15:22:41 +02:00
[Option("db-password", HelpText = "Set a posgresql password (default: empty) (env: DB_PASSWORD)")]
public string DbPassword { get ; set ; } = ParamFallback ( "DB_PASSWORD" , "" ) ;
2020-06-19 21:46:19 +02:00
[Option("db-require-ssl", HelpText = "Require SSL to connect to the database (default: false) (env: DB_REQUIRE_SSL)")]
public bool DbSsl { get ; set ; } = ParamFallback ( "DB_REQUIRE_SSL" , false ) ;
[Option("db-trust-cert", HelpText = "Trust the database certificate, regardless if it is valid (default: false) (env: DB_TRUST_CERT)")]
public bool DbTrustCert { get ; set ; } = ParamFallback ( "DB_TRUST_CERT" , false ) ;
2020-06-20 03:05:51 +02:00
[Option("db-redshift-compat", HelpText = "Enable compatibility for AWS Redshift and DigitalOcean Managed Database (default: false) (env: DB_REDSHIFT_COMPAT)")]
public bool DbRedshiftCompatibility { get ; set ; } = ParamFallback ( "DB_REDSHIFT_COMPAT" , false ) ;
2019-01-27 22:08:49 +01:00
// Logging
2020-06-01 15:22:41 +02:00
[Option("db-logging", HelpText = "Enable database logging (default: false) (env: DB_LOGGING)")]
public bool DbLogging { get ; set ; } = ParamFallback ( "DB_LOGGING" , false ) ;
2018-05-13 18:47:01 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* WebApi *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2020-06-01 15:22:41 +02:00
[Option('a', "disable-api", HelpText = "Disables the WebApi (default: false) (env: API_DISABLE)")]
public bool DisableApi { get ; set ; } = ParamFallback ( "API_DISABLE" , false ) ;
[Option("api-host", HelpText = "Host on which the WebApi listens (default: localhost) (env: API_HOST)")]
public string ApiHost { get ; set ; } = ParamFallback ( "API_HOST" , "localhost" ) ;
[Option("api-port", HelpText = "Port on which the WebApi listens (default: 12995) (env: API_PORT)")]
public string ApiPort { get ; set ; } = ParamFallback ( "API_PORT" , "12995" ) ;
2020-06-20 00:20:00 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Intergrations *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
[Option("sumologic", HelpText = "Sumologic endpoint for logging (default: null) (env: SUMOLOGIC)")]
public string SumologicEndpoint { get ; set ; } = ParamFallback ( "SUMOLOGIC" ) ;
[Option("sentry", HelpText = "Sentry endpoint for error reporting (default: null) (env: SENTRY)")]
public string SentryEndpoint { get ; set ; } = ParamFallback ( "SENTRY" ) ;
2020-06-01 15:22:41 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Helper Functions *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
private static string ParamFallback ( string key , string defaultValue = null )
{
var envVar = GetEnvironmentVariable ( key ) ;
return ! string . IsNullOrEmpty ( envVar ) ? envVar : defaultValue ;
}
private static bool ParamFallback ( string key , bool defaultValue )
{
var envVar = GetEnvironmentVariable ( key ) ;
if ( ! string . IsNullOrEmpty ( envVar ) )
{
return envVar . ToLower ( ) switch
{
"true" = > true ,
"1" = > true ,
"false" = > false ,
"0" = > false ,
_ = > defaultValue
} ;
}
return defaultValue ;
}
private static string GetEnvironmentVariable ( string name )
{
return Environment . GetEnvironmentVariable ( $"GEEKBOT_{name}" ) ;
}
2018-05-02 20:19:11 +02:00
}
}