From 96d0afeb4c8c5fffc9e1f61e2e8e4e0333f18dd7 Mon Sep 17 00:00:00 2001 From: Josua Bryner <16536859+josi19@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:07:59 +0200 Subject: [PATCH] display defaults/placeholders for mysql update and create commands --- create/mysql.go | 27 +++++++++++++++++---------- go.mod | 2 +- go.sum | 4 ++++ update/mysql.go | 18 +++++++++--------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/create/mysql.go b/create/mysql.go index ce1227b..09d9f70 100644 --- a/create/mysql.go +++ b/create/mysql.go @@ -21,18 +21,18 @@ import ( type mySQLCmd struct { Name string `arg:"" default:"" help:"Name of the MySQL instance. A random name is generated if omitted."` - Location string `default:"${mysql_location_default}" help:"Location where the MySQL instance is created. Currently available locations are: ${mysql_location_options}"` - MachineType infra.MachineType `help:"Defines the sizing for a particular MySQL instance." placeholder:"nine-standard-1" default:"nine-standard-1"` - AllowedCidrs []storage.IPv4CIDR `help:"Specifies the IP addresses allowed to connect to the instance." placeholder:"0.0.0.0/0"` + Location string `placeholder:"${mysql_location_default}" help:"Location where the MySQL instance is created. Available locations are: ${mysql_location_options}"` + MachineType infra.MachineType `placeholder:"${mysql_machine_default}" help:"Defines the sizing for a particular MySQL instance. Available types: ${mysql_machine_types}"` + AllowedCidrs []storage.IPv4CIDR `placeholder:"0.0.0.0/0" help:"Specifies the IP addresses allowed to connect to the instance." ` SSHKeys []storage.SSHKey `help:"Contains a list of SSH public keys, allowed to connect to the db server, in order to up-/download and directly restore database backups."` SSHKeysFile string `help:"Path to a file containing a list of SSH public keys (see above), separated by newlines."` - SQLMode *[]storage.MySQLMode `default:"<\"MODE1, MODE2, ...\">" help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs. Defaults to: ${mysql_mode}"` - CharacterSetName string `default:"${mysql_charset}" help:"Configures the character_set_server variable."` - CharacterSetCollation string `default:"${mysql_collation}" help:"Configures the collation_server variable."` - LongQueryTime storage.LongQueryTime `default:"${mysql_long_query_time}" help:"Configures the long_query_time variable. If a query takes longer than this duration, the query is logged to the slow query log file."` - MinWordLength *int `default:"${mysql_min_word_length}" help:"Configures the ft_min_word_len and innodb_ft_min_token_size variables."` - TransactionIsolation storage.MySQLTransactionCharacteristic `default:"${mysql_transaction_isolation}" help:"Configures the transaction_isolation variable."` - KeepDailyBackups *int `default:"${mysql_backup_retention_days}" help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."` + SQLMode *[]storage.MySQLMode `placeholder:"\"MODE1, MODE2, ...\"" help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs. Defaults to: ${mysql_mode}"` + CharacterSetName string `placeholder:"${mysql_charset}" help:"Configures the character_set_server variable."` + CharacterSetCollation string `placeholder:"${mysql_collation}" help:"Configures the collation_server variable."` + LongQueryTime storage.LongQueryTime `placeholder:"${mysql_long_query_time}" help:"Configures the long_query_time variable. If a query takes longer than this duration, the query is logged to the slow query log file."` + MinWordLength *int `placeholder:"${mysql_min_word_length}" help:"Configures the ft_min_word_len and innodb_ft_min_token_size variables."` + TransactionIsolation storage.MySQLTransactionCharacteristic `placeholder:"${mysql_transaction_isolation}" help:"Configures the transaction_isolation variable."` + KeepDailyBackups *int `placeholder:"${mysql_backup_retention_days}" help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."` Wait bool `default:"true" help:"Wait until MySQL instance is created."` WaitTimeout time.Duration `default:"900s" help:"Duration to wait for MySQL getting ready. Only relevant if --wait is set."` } @@ -119,7 +119,14 @@ func (cmd *mySQLCmd) newMySQL(namespace string) *storage.MySQL { // ApplicationKongVars returns all variables which are used in the application // create command func MySQLKongVars() (kong.Vars, error) { + vmTypes := make([]string, len(infra.MachineTypes)) + for i, machineType := range infra.MachineTypes { + vmTypes[i] = string(machineType) + } + result := make(kong.Vars) + result["mysql_machine_types"] = strings.Join(vmTypes, ", ") + result["mysql_machine_default"] = string(infra.MachineTypes[0]) result["mysql_location_options"] = strings.Join(storage.MySQLLocationOptions, ", ") result["mysql_location_default"] = string(storage.MySQLLocationDefault) result["mysql_user"] = string(storage.MySQLUser) diff --git a/go.mod b/go.mod index b58293d..00b0fc2 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/mattn/go-isatty v0.0.20 github.com/moby/moby v26.0.0+incompatible github.com/moby/term v0.5.0 - github.com/ninech/apis v0.0.0-20240417150103-d7d5bf5ca446 + github.com/ninech/apis v0.0.0-20240418155256-94a608198745 github.com/posener/complete v1.2.3 github.com/prometheus/common v0.52.2 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 3a97210..48c5b99 100644 --- a/go.sum +++ b/go.sum @@ -590,6 +590,10 @@ github.com/ninech/apis v0.0.0-20240415094850-e5c1ffdfaebc h1:nsDzgqsA7k3umT1j6lt github.com/ninech/apis v0.0.0-20240415094850-e5c1ffdfaebc/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is= github.com/ninech/apis v0.0.0-20240417150103-d7d5bf5ca446 h1:Hzqrx0AzrYKIM9DH1vPlNSSOm3NGIUg9QXGm0P9S1Bs= github.com/ninech/apis v0.0.0-20240417150103-d7d5bf5ca446/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is= +github.com/ninech/apis v0.0.0-20240418132238-3fd74f5b0ebf h1:+/Y7rKMzxm7KIGHa8/wZpqI/bGandUY3KpEsigpJIoo= +github.com/ninech/apis v0.0.0-20240418132238-3fd74f5b0ebf/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is= +github.com/ninech/apis v0.0.0-20240418155256-94a608198745 h1:Oz5E/uiGwYVYPsFHohyCAFwzLbe92sqW+MHf+cNx1Fk= +github.com/ninech/apis v0.0.0-20240418155256-94a608198745/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= diff --git a/update/mysql.go b/update/mysql.go index 0c98060..d82e376 100644 --- a/update/mysql.go +++ b/update/mysql.go @@ -14,17 +14,17 @@ import ( type mySQLCmd struct { Name string `arg:"" default:"" help:"Name of the MySQL instance to update."` - MachineType *infra.MachineType `help:"Defines the sizing for a particular MySQL instance."` - AllowedCidrs *[]storage.IPv4CIDR `default:"" help:"Specifies the IP addresses allowed to connect to the instance."` + MachineType *infra.MachineType `placeholder:"${mysql_machine_default}" help:"Defines the sizing for a particular MySQL instance. Available types: ${mysql_machine_types}"` + AllowedCidrs *[]storage.IPv4CIDR `placeholder:"0.0.0.0/0" help:"Specifies the IP addresses allowed to connect to the instance." ` SSHKeys []storage.SSHKey `help:"Contains a list of SSH public keys, allowed to connect to the db server, in order to up-/download and directly restore database backups."` SSHKeysFile string `help:"Path to a file containing a list of SSH public keys (see above), separated by newlines."` - SQLMode *[]storage.MySQLMode `help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs."` - CharacterSetName *string `help:"Configures the character_set_server variable."` - CharacterSetCollation *string `help:"Configures the collation_server variable."` - LongQueryTime *storage.LongQueryTime `help:"Configures the long_query_time variable. If a query takes longer than this duration, the query is logged to the slow query log file."` - MinWordLength *int `help:"Configures the ft_min_word_len and innodb_ft_min_token_size variables."` - TransactionIsolation *storage.MySQLTransactionCharacteristic `help:"Configures the transaction_isolation variable."` - KeepDailyBackups *int `help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."` + SQLMode *[]storage.MySQLMode `placeholder:"\"MODE1, MODE2, ...\"" help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs. Defaults to: ${mysql_mode}"` + CharacterSetName *string `placeholder:"${mysql_charset}" help:"Configures the character_set_server variable."` + CharacterSetCollation *string `placeholder:"${mysql_collation}" help:"Configures the collation_server variable."` + LongQueryTime *storage.LongQueryTime `placeholder:"${mysql_long_query_time}" help:"Configures the long_query_time variable. If a query takes longer than this duration, the query is logged to the slow query log file."` + MinWordLength *int `placeholder:"${mysql_min_word_length}" help:"Configures the ft_min_word_len and innodb_ft_min_token_size variables."` + TransactionIsolation *storage.MySQLTransactionCharacteristic `placeholder:"${mysql_transaction_isolation}" help:"Configures the transaction_isolation variable."` + KeepDailyBackups *int `placeholder:"${mysql_backup_retention_days}" help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."` } func (cmd *mySQLCmd) Run(ctx context.Context, client *api.Client) error {