Skip to content

Commit

Permalink
Merge pull request #587 from rsteube/comments-fixes
Browse files Browse the repository at this point in the history
fix comment style
  • Loading branch information
rsteube committed Nov 12, 2022
2 parents 168384d + 996b85d commit cfbaaa1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 10 additions & 10 deletions carapace.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
"github.com/spf13/pflag"
)

// Carapace wraps cobra.Command to define completions
// Carapace wraps cobra.Command to define completions.
type Carapace struct {
cmd *cobra.Command
}

// Gen initialized Carapace for given command
// Gen initialized Carapace for given command.
func Gen(cmd *cobra.Command) *Carapace {
addCompletionCommand(cmd)

Expand Down Expand Up @@ -73,27 +73,27 @@ func (c Carapace) PreInvoke(f func(cmd *cobra.Command, flag *pflag.Flag, action
}
}

// PositionalCompletion defines completion for positional arguments using a list of Actions
// PositionalCompletion defines completion for positional arguments using a list of Actions.
func (c Carapace) PositionalCompletion(action ...Action) {
storage.get(c.cmd).positional = action
}

// PositionalAnyCompletion defines completion for any positional arguments not already defined
// PositionalAnyCompletion defines completion for any positional arguments not already defined.
func (c Carapace) PositionalAnyCompletion(action Action) {
storage.get(c.cmd).positionalAny = action
}

// DashCompletion defines completion for positional arguments after dash (`--`) using a list of Actions
// DashCompletion defines completion for positional arguments after dash (`--`) using a list of Actions.
func (c Carapace) DashCompletion(action ...Action) {
storage.get(c.cmd).dash = action
}

// DashAnyCompletion defines completion for any positional arguments after dash (`--`) not already defined
// DashAnyCompletion defines completion for any positional arguments after dash (`--`) not already defined.
func (c Carapace) DashAnyCompletion(action Action) {
storage.get(c.cmd).dashAny = action
}

// FlagCompletion defines completion for flags using a map consisting of name and Action
// FlagCompletion defines completion for flags using a map consisting of name and Action.
func (c Carapace) FlagCompletion(actions ActionMap) {
if e := storage.get(c.cmd); e.flag == nil {
e.flag = actions
Expand All @@ -104,7 +104,7 @@ func (c Carapace) FlagCompletion(actions ActionMap) {
}
}

// Standalone prevents cobra defaults interfering with standalone mode (e.g. implicit help command)
// Standalone prevents cobra defaults interfering with standalone mode (e.g. implicit help command).
func (c Carapace) Standalone() {
c.cmd.CompletionOptions = cobra.CompletionOptions{
DisableDefaultCmd: true,
Expand All @@ -118,7 +118,7 @@ func (c Carapace) Standalone() {
c.cmd.SetHelpCommand(&cobra.Command{Hidden: true})
}

// Snippet creates completion script for given shell
// Snippet creates completion script for given shell.
func (c Carapace) Snippet(shell string) (string, error) {
if shell == "" {
shell = ps.DetermineShell()
Expand Down Expand Up @@ -150,7 +150,7 @@ func (c Carapace) Snippet(shell string) (string, error) {
return "", fmt.Errorf("expected one of '%v' [was: %v]", strings.Join(expected, "', '"), shell)
}

// IsCallback returns true if current program invocation is a callback
// IsCallback returns true if current program invocation is a callback.
func IsCallback() bool {
return len(os.Args) > 1 && os.Args[1] == "_carapace"
}
Expand Down
3 changes: 3 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func addCompletionCommand(cmd *cobra.Command) {
return
}
}

carapaceCmd := &cobra.Command{
Use: "_carapace",
Hidden: true,
Expand All @@ -38,7 +39,9 @@ func addCompletionCommand(cmd *cobra.Command) {
},
DisableFlagParsing: true,
}

cmd.AddCommand(carapaceCmd)

Carapace{carapaceCmd}.PositionalCompletion(
ActionStyledValues(
"bash", "#d35673",
Expand Down
3 changes: 1 addition & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rsteube/carapace/third_party/golang.org/x/sys/execabs"
)

// Context provides information during completion
// Context provides information during completion.
type Context struct {
// CallbackValue contains the (partial) value (or part of it during an ActionMultiParts) currently being completed
CallbackValue string
Expand All @@ -34,7 +34,6 @@ func (c *Context) LookupEnv(key string) (string, bool) {
}
}
return "", false

}

// Getenv retrieves the value of the environment variable named by the key.
Expand Down

0 comments on commit cfbaaa1

Please sign in to comment.