refactor(ansible): clarify CLI helper naming
Some checks are pending
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run
CI / auto-merge (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 13:18:36 +00:00
parent 2dc29d1592
commit 65cd1b9e01
2 changed files with 13 additions and 11 deletions

View file

@ -15,7 +15,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
type playbookCommandSettings struct { type playbookCommandOptions struct {
playbookPath string playbookPath string
basePath string basePath string
limit string limit string
@ -280,18 +280,20 @@ func parseExtraVarsScalar(value string) any {
return value return value
} }
// resolveTestSSHKeyFile resolves the SSH key flag used by the ansible test subcommand. // Example:
func resolveTestSSHKeyFile(opts core.Options) string { //
// core ansible test server.example.com -i ~/.ssh/id_ed25519
func resolveSSHTestKeyFile(opts core.Options) string {
if key := opts.String("key"); key != "" { if key := opts.String("key"); key != "" {
return key return key
} }
return opts.String("i") return opts.String("i")
} }
func buildPlaybookCommandSettings(opts core.Options, rawArgs []string) (playbookCommandSettings, error) { func buildPlaybookCommandSettings(opts core.Options, rawArgs []string) (playbookCommandOptions, error) {
positional := positionalArgs(opts) positional := positionalArgs(opts)
if len(positional) < 1 { if len(positional) < 1 {
return playbookCommandSettings{}, coreerr.E("buildPlaybookCommandSettings", "usage: ansible <playbook>", nil) return playbookCommandOptions{}, coreerr.E("buildPlaybookCommandSettings", "usage: ansible <playbook>", nil)
} }
playbookPath := positional[0] playbookPath := positional[0]
@ -300,15 +302,15 @@ func buildPlaybookCommandSettings(opts core.Options, rawArgs []string) (playbook
} }
if !coreio.Local.Exists(playbookPath) { if !coreio.Local.Exists(playbookPath) {
return playbookCommandSettings{}, coreerr.E("buildPlaybookCommandSettings", sprintf("playbook not found: %s", playbookPath), nil) return playbookCommandOptions{}, coreerr.E("buildPlaybookCommandSettings", sprintf("playbook not found: %s", playbookPath), nil)
} }
vars, err := extraVars(opts) vars, err := extraVars(opts)
if err != nil { if err != nil {
return playbookCommandSettings{}, coreerr.E("buildPlaybookCommandSettings", "parse extra vars", err) return playbookCommandOptions{}, coreerr.E("buildPlaybookCommandSettings", "parse extra vars", err)
} }
return playbookCommandSettings{ return playbookCommandOptions{
playbookPath: playbookPath, playbookPath: playbookPath,
basePath: pathDir(playbookPath), basePath: pathDir(playbookPath),
limit: joinedStringOption(opts, "limit", "l"), limit: joinedStringOption(opts, "limit", "l"),
@ -473,7 +475,7 @@ func runSSHTestCommand(opts core.Options) core.Result {
Port: opts.Int("port"), Port: opts.Int("port"),
User: firstStringOption(opts, "user", "u"), User: firstStringOption(opts, "user", "u"),
Password: opts.String("password"), Password: opts.String("password"),
KeyFile: resolveTestSSHKeyFile(opts), KeyFile: resolveSSHTestKeyFile(opts),
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
} }

View file

@ -253,7 +253,7 @@ func TestTestKeyFile_Good_PrefersExplicitKey(t *testing.T) {
core.Option{Key: "i", Value: "/tmp/ignored"}, core.Option{Key: "i", Value: "/tmp/ignored"},
) )
assert.Equal(t, "/tmp/id_ed25519", resolveTestSSHKeyFile(opts)) assert.Equal(t, "/tmp/id_ed25519", resolveSSHTestKeyFile(opts))
} }
func TestTestKeyFile_Good_FallsBackToShortAlias(t *testing.T) { func TestTestKeyFile_Good_FallsBackToShortAlias(t *testing.T) {
@ -261,7 +261,7 @@ func TestTestKeyFile_Good_FallsBackToShortAlias(t *testing.T) {
core.Option{Key: "i", Value: "/tmp/id_ed25519"}, core.Option{Key: "i", Value: "/tmp/id_ed25519"},
) )
assert.Equal(t, "/tmp/id_ed25519", resolveTestSSHKeyFile(opts)) assert.Equal(t, "/tmp/id_ed25519", resolveSSHTestKeyFile(opts))
} }
func TestFirstString_Good_ResolvesShortUserAlias(t *testing.T) { func TestFirstString_Good_ResolvesShortUserAlias(t *testing.T) {