Skip to content

Commit

Permalink
git: rev-list
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Aug 16, 2024
1 parent da21659 commit ee60f15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 77 deletions.
12 changes: 0 additions & 12 deletions completers/git_completer/cmd/pretty.txt

This file was deleted.

76 changes: 11 additions & 65 deletions completers/git_completer/cmd/revList.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package cmd

import (
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/git_completer/cmd/common"
"github.com/carapace-sh/carapace-bin/pkg/actions/time"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)
Expand All @@ -20,76 +17,25 @@ var revListCmd = &cobra.Command{
func init() {
carapace.Gen(revListCmd).Standalone()

common.AddCommitLimitingOptions(revListCmd)
common.AddHistorySimplificationOptions(revListCmd)
common.AddBisectionHelperOptions(revListCmd)
common.AddCommitFormattingOptions(revListCmd)
common.AddCommitLimitingOptions(revListCmd)
common.AddCommitOrderingOptions(revListCmd)
common.AddHistorySimplificationOptions(revListCmd)
common.AddObjectTraversalOptions(revListCmd)
common.AddCommitFormattingOptions(revListCmd)
rootCmd.AddCommand(revListCmd)

// TODO move
revListCmd.Flag("pretty").NoOptDefVal = " "

// TODO still a lot of completions missing / incorrect
// TODO move
carapace.Gen(revListCmd).FlagCompletion(carapace.ActionMap{
"author": git.ActionAuthors(),
"branches": git.ActionLocalBranches(),
"committer": git.ActionCommitters(),
"date": carapace.ActionValuesDescribed(
"relative", "shows dates relative to the current time",
"local", "is an alias for --date=default-local",
"iso", "shows timestamps in a ISO 8601-like format",
"iso8601", "shows timestamps in a ISO 8601-like format",
"iso-strict", "shows timestamps in strict ISO 8601 format",
"iso8601-strict", "shows timestamps in strict ISO 8601 format",
"rfc", "shows timestamps in RFC 2822 format",
"rfc2822", "shows timestamps in RFC 2822 format",
"short", "shows only the date, but not the time, in YYYY-MM-DD format",
"raw", "shows the date as seconds since the epoch (1970-01-01 00:00:00 UTC)",
"human", "shows the date in human readable format",
"unix", "shows the date as a Unix epoch timestamp (seconds since 1970)",
"format:", "feeds the given format to your system strftime",
"format:%c", "show the date in your system locale’s preferred format",
"default", "the default format",
),
"disk-usage": carapace.ActionValues("human"),
"exclude": carapace.Batch(
git.ActionLocalBranches(),
git.ActionTags(),
git.ActionRemotes(),
).ToA(),
"exclude-hidden": carapace.ActionValues("receive", "uploadpack"),
"format": carapace.ActionValues("oneline", "short", "medium", "full", "fuller", "reference", "email", "raw", "format:"),
"missing": carapace.ActionValues(
"error", "requests that rev-list stop with an error if a missing object is encountered",
"allow-any", "allow object traversal to continue if a missing object is encountered",
"allow-promisor", "is like allow-any, but will only allow object traversal to continue for EXPECTED promisor missing objects",
"print", "is like allow-any, but will also print a list of the missing objects",
),
"no-walk": carapace.ActionValues("sorted", "unsorted"),
"pretty": carapace.ActionValues("oneline", "short", "medium", "full", "fuller", "reference", "email", "raw", "format:"),
"remotes": git.ActionRemotes(),
"since": time.ActionDate(),
"since-as-filter": time.ActionDate(),
"tags": git.ActionTags(),
"until": time.ActionDate(),
})

carapace.Gen(revListCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
prefix := ""
if strings.HasPrefix(c.Value, "^") {
prefix = "^"
}

c.Value = strings.TrimPrefix(c.Value, prefix)
return git.ActionRefs(git.RefOption{}.Default()).Invoke(c).Prefix(prefix).ToA()
}),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(revListCmd).DashAnyCompletion(
carapace.ActionFiles(),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
batch := carapace.Batch()
for _, ref := range revListCmd.Flags().Args()[:revListCmd.Flags().ArgsLenAtDash()] {
batch = append(batch, git.ActionRefFiles(ref))
}
return batch.ToA()
}),
)
}

0 comments on commit ee60f15

Please sign in to comment.