Skip to content

Commit

Permalink
display defaults/placeholders for mysql update and create commands
Browse files Browse the repository at this point in the history
  • Loading branch information
josi19 committed Apr 19, 2024
1 parent 05f80e7 commit 96d0afe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
27 changes: 17 additions & 10 deletions create/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 9 additions & 9 deletions update/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 96d0afe

Please sign in to comment.