Skip to content

Commit 12888bb

Browse files
committed
Make PrependArgs opt-in for MySQL only
Add a PrependArgs FileOption that allows specific plugins to opt into prepending arguments instead of appending. This preserves the default AddArgs behavior for all other plugins while allowing MySQL to place --defaults-file first as required by the mysql CLI.
1 parent 66899fa commit 12888bb

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

plugins/mysql/database_credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func DatabaseCredentials() schema.CredentialType {
4343
Optional: true,
4444
},
4545
},
46-
DefaultProvisioner: provision.TempFile(mysqlConfig, provision.Filename("my.cnf"), provision.AddArgs("--defaults-file={{ .Path }}")),
46+
DefaultProvisioner: provision.TempFile(mysqlConfig, provision.Filename("my.cnf"), provision.PrependArgs("--defaults-file={{ .Path }}")),
4747
Importer: importer.TryAll(
4848
TryMySQLConfigFile("/etc/my.cnf"),
4949
TryMySQLConfigFile("/etc/mysql/my.cnf"),

sdk/provision/file_provisioner.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type FileProvisioner struct {
2121
outpathEnvVar string
2222
outdirEnvVar string
2323
setOutpathAsArg bool
24+
prependArgs bool
2425
outpathArgTemplates []string
2526
}
2627

@@ -95,6 +96,19 @@ func AddArgs(argTemplates ...string) FileOption {
9596
}
9697
}
9798

99+
// PrependArgs can be used to prepend args to the command line, placing them before any user-provided arguments.
100+
// This is useful for CLIs like mysql that require certain arguments (e.g., --defaults-file) to be the very first argument.
101+
// The output path is available as "{{ .Path }}" in each arg.
102+
// For example:
103+
// * `PrependArgs("--defaults-file={{ .Path }}")` will result in `--defaults-file=/path/to/tempfile` being placed first.
104+
func PrependArgs(argTemplates ...string) FileOption {
105+
return func(p *FileProvisioner) {
106+
p.setOutpathAsArg = true
107+
p.prependArgs = true
108+
p.outpathArgTemplates = argTemplates
109+
}
110+
}
111+
98112
func (p FileProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) {
99113
contents, err := p.fileContents(in)
100114
if err != nil {
@@ -159,7 +173,11 @@ func (p FileProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, o
159173
argsResolved[i] = result.String()
160174
}
161175

162-
out.PrependArgs(argsResolved...)
176+
if p.prependArgs {
177+
out.PrependArgs(argsResolved...)
178+
} else {
179+
out.AddArgs(argsResolved...)
180+
}
163181
}
164182
}
165183

0 commit comments

Comments
 (0)