Archived
1
This commit is contained in:
2024-12-19 18:48:26 +03:00
commit 2186f92263
32 changed files with 1498 additions and 0 deletions

36
cmd/utils.go Normal file
View File

@@ -0,0 +1,36 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"os"
"path/filepath"
"playbookctl/internal/types"
)
func ArgRoleCompletion(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
exitApp := func(err error) {
fmt.Println(err)
os.Exit(1)
}
var suggestions []string
workDir, err := filepath.Abs(flagWorkdir)
if err != nil {
exitApp(err)
}
playbook, err := types.ReadPlaybook(workDir)
if err != nil {
exitApp(err)
}
for _, role := range playbook.Roles {
if toComplete == "" || len(role) >= len(toComplete) && role[:len(toComplete)] == toComplete {
suggestions = append(suggestions, role)
}
}
return suggestions, cobra.ShellCompDirectiveDefault
}