commit 3be32d581e10d2bcac610c160093b5d4058fcb4b parent 0700f4e861d722f20394d69900705e4807773a1d Author: Sean Enck <sean@ttypty.com> Date: Wed, 25 Sep 2024 19:47:41 -0400 restructure shell completion files Diffstat:
6 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/internal/app/completions.go b/internal/app/completions.go @@ -3,6 +3,7 @@ package app import ( "bytes" + "embed" "fmt" "slices" "strings" @@ -49,6 +50,9 @@ type ( } ) +//go:embed shell/* +var shell embed.FS + // Options will list the profile options func (p Profile) Options() []string { opts := []string{EnvCommand, HelpCommand, ListCommand, ShowCommand, VersionCommand, JSONCommand} @@ -139,11 +143,11 @@ func GenerateCompletions(completionType, exe string) ([]string, error) { IsFish: completionType == CompletionsFishCommand, } - using, err := readDoc(fmt.Sprintf("%s.sh", completionType)) + using, err := readShell(completionType) if err != nil { return nil, err } - shellScript, err := readDoc("shell.sh") + shellScript, err := readShell("shell") if err != nil { return nil, err } @@ -166,6 +170,10 @@ func GenerateCompletions(completionType, exe string) ([]string, error) { return []string{s}, nil } +func readShell(file string) (string, error) { + return readEmbedded(fmt.Sprintf("%s.sh", file), "shell", shell) +} + func templateScript(script string, c Completions) (string, error) { t, err := template.New("t").Parse(script) if err != nil { diff --git a/internal/app/core.go b/internal/app/core.go @@ -274,7 +274,7 @@ func Usage(verbose bool, exe string) ([]string, error) { } func processDoc(header, file string, doc Documentation) (string, error) { - b, err := readDoc(file) + b, err := readEmbedded(file, docDir, docs) if err != nil { return "", err } @@ -293,8 +293,8 @@ func setDocFlag(f string) string { return fmt.Sprintf("-%s=", f) } -func readDoc(doc string) (string, error) { - b, err := docs.ReadFile(filepath.Join(docDir, doc)) +func readEmbedded(file, dir string, e embed.FS) (string, error) { + b, err := e.ReadFile(filepath.Join(dir, file)) if err != nil { return "", err } diff --git a/internal/app/doc/bash.sh b/internal/app/shell/bash.sh diff --git a/internal/app/doc/fish.sh b/internal/app/shell/fish.sh diff --git a/internal/app/doc/shell.sh b/internal/app/shell/shell.sh diff --git a/internal/app/doc/zsh.sh b/internal/app/shell/zsh.sh