command.go
This file
Path
completion/command.go
60 lines · 1.3 KiB · Go
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6837ed2 point at it.
feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 1–60why, one step back1package completion23import (4 "fmt"5 "io"6 "os"7 "strings"89 "github.com/alecthomas/kong"10)1112// Completion command.13type Completion struct {14 Bash Bash `cmd:"" help:"Generate the autocompletion script for bash"`15 Zsh Zsh `cmd:"" help:"Generate the autocompletion script for zsh"`16 Fish Fish `cmd:"" help:"Generate the autocompletion script for fish"`17}1819func commandName(cmd *kong.Node) string {20 commandName := cmd.FullPath()21 commandName = strings.ReplaceAll(commandName, " ", "_")22 commandName = strings.ReplaceAll(commandName, ":", "__")23 return commandName24}2526func hasCommands(cmd *kong.Node) bool {27 for _, c := range cmd.Children {28 if !c.Hidden {29 return true30 }31 }32 return false33}3435//nolint:deadcode,unused36func isArgument(cmd *kong.Node) bool {37 return cmd.Type == kong.ArgumentNode38}3940// writeString writes a string into a buffer, and checks if the error is not nil.41func writeString(b io.StringWriter, s string) {42 if _, err := b.WriteString(s); err != nil {43 fmt.Fprintln(os.Stderr, "Error:", err)44 os.Exit(1)45 }46}4748func nonCompletableFlag(flag *kong.Flag) bool {49 return flag.Hidden50}5152func flagPossibleValues(flag *kong.Flag) []string {53 values := make([]string, 0)54 for _, enum := range flag.EnumSlice() {55 if strings.TrimSpace(enum) != "" {56 values = append(values, enum)57 }58 }59 return values60}