Skip to content

Commit

Permalink
git: help
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Oct 29, 2023
1 parent 1f05a76 commit 404342d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 25 deletions.
38 changes: 38 additions & 0 deletions completers/git_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)

var helpCmd = &cobra.Command{
Use: "help",
Short: "Display help information about Git",
Run: func(cmd *cobra.Command, args []string) {},
GroupID: groups[group_interrogator].ID,
}

func init() {
carapace.Gen(helpCmd).Standalone()

helpCmd.Flags().BoolP("all", "a", false, "Prints all the available commands on the standard output")
helpCmd.Flags().BoolP("config", "c", false, "List all available configuration variables")
helpCmd.Flags().Bool("developer-interfaces", false, "Print list of file formats, protocols and other developer interfaces documentation")
helpCmd.Flags().BoolP("guides", "g", false, "Prints a list of the Git concept guides on the standard output")
helpCmd.Flags().BoolP("info", "i", false, "Display manual page for the command in the info format")
helpCmd.Flags().BoolP("man", "m", false, "Display manual page for the command in the man format")
helpCmd.Flags().Bool("no-aliases", false, "Exclude the listing of configured aliases")
helpCmd.Flags().Bool("no-external-commands", false, "Exclude the listing of external \"git-*\" commands found in the $PATH")
helpCmd.Flags().Bool("user-interfaces", false, "Prints a list of the repository, command and file interfaces documentation")
helpCmd.Flags().Bool("verbose", false, "Print description for all recognized commands")
helpCmd.Flags().BoolP("web", "w", false, "Display manual page for the command in the web (HTML) format")
rootCmd.AddCommand(helpCmd)

carapace.Gen(helpCmd).PositionalCompletion(
carapace.Batch(
carapace.ActionCommands(rootCmd),
git.ActionDeveloperInterfaces(),
).ToA(),
)
}
25 changes: 0 additions & 25 deletions completers/git_completer/cmd/help_generated.go

This file was deleted.

27 changes: 27 additions & 0 deletions pkg/actions/tools/git/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package git

import (
"regexp"
"strings"

"github.com/rsteube/carapace"
)

// ActionDeveloperInterfaces completes developer interfaces
//
// format-bundle (The bundle file format)
// format-chunk (Chunk-based file formats)
func ActionDeveloperInterfaces() carapace.Action {
return carapace.ActionExecCommand("git", "help", "--developer-interfaces")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^ (?P<interfaces>[^ ]+) +(?P<description>.*)$`)

vals := make([]string, 0)
for _, line := range lines {
if matches := r.FindStringSubmatch(line); matches != nil {
vals = append(vals, matches[1], matches[2])
}
}
return carapace.ActionValuesDescribed(vals...)
}).Tag("developer interfaces")
}

0 comments on commit 404342d

Please sign in to comment.