Skip to content

Commit

Permalink
git: move actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 27, 2023
1 parent bccfb45 commit 003af01
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 69 deletions.
3 changes: 1 addition & 2 deletions completers/git_completer/cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -51,7 +50,7 @@ func init() {

carapace.Gen(branchCmd).FlagCompletion(carapace.ActionMap{
"D": git.ActionRefs(git.RefOption{}.Default()),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"color": git.ActionColorModes(),
"contains": git.ActionRefs(git.RefOption{}.Default()),
"delete": git.ActionRefs(git.RefOption{LocalBranches: true, RemoteBranches: true}),
"merged": git.ActionRefs(git.RefOption{}.Default()),
Expand Down
65 changes: 6 additions & 59 deletions completers/git_completer/cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace-bin/pkg/util"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -122,69 +121,17 @@ func addDiffFlags(cmd *cobra.Command) {
cmd.Flag("word-diff").NoOptDefVal = "plain"

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"color-moved": ActionColorMovedModes(),
"color-moved-ws": ActionColorMovedWsModes(),
"diff-algorithm": ActionDiffAlgorithms(),
"color": git.ActionColorModes(),
"color-moved": git.ActionColorMovedModes(),
"color-moved-ws": git.ActionColorMovedWsModes(),
"diff-algorithm": git.ActionDiffAlgorithms(),
"output": carapace.ActionFiles(),
"submodule": carapace.ActionValues("short", "long", "log"),
"word-diff": ActionWordDiffModes(),
"ws-error-highlight": ActionWsErrorHighlightModes().UniqueList(","),
"word-diff": git.ActionWordDiffModes(),
"ws-error-highlight": git.ActionWsErrorHighlightModes().UniqueList(","),
})

carapace.Gen(cmd).DashAnyCompletion(
carapace.ActionFiles(),
)

}

func ActionDiffAlgorithms() carapace.Action {
return carapace.ActionValuesDescribed(
"myers", "The basic greedy diff algorithm",
"minimal", "Spend extra time to make sure the smallest possible diff is produced",
"patience",
"Use patience diff algorithm when generating patches",
"histogram", "This algorithm extends the patience algorithm to support low-occurrence common elements",
)
}

func ActionColorMovedModes() carapace.Action {
return carapace.ActionValuesDescribed(
"no", "Moved lines are not highlighted",
"default", "default mode",
"plain", "plain mode",
"blocks", "greedily detects blocks",
"zebra", "Blocks of moved text are detected as in blocks mode",
"dimmed-zebra", "Similar to zebra, but additional dimming of uninteresting parts of moved code",
)
}

func ActionColorMovedWsModes() carapace.Action {
return carapace.ActionValuesDescribed(
"no", "Do not ignore whitespace when performing move detection",
"ignore-space-at-eol", "Ignore changes in whitespace at EOL",
"ignore-space-change", "Ignore changes in amount of whitespace.",
"ignore-all-space", "Ignore whitespace when comparing lines.",
"allow-indentation-change", "Initially ignore any whitespace in the move detection",
)
}

func ActionWordDiffModes() carapace.Action {
return carapace.ActionValuesDescribed(
"color", "Highlight changed words using only colors",
"plain", "Show words as [-removed-] and {+added+}",
"porcelain", "Use a special line-based format intended for script consumption",
"none", "Disable word diff again",
)
}

func ActionWsErrorHighlightModes() carapace.Action {
return carapace.ActionValuesDescribed(
"context", "context lines",
"old", "old lines",
"new", "new linex",
"none", "reset previous values",
"default", "reset to new",
"all", "shorthand for old,new,context",
)
}
3 changes: 1 addition & 2 deletions completers/git_completer/cmd/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/os"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -69,7 +68,7 @@ func init() {
grepCmd.Flag("open-files-in-pager").NoOptDefVal = " "

carapace.Gen(grepCmd).FlagCompletion(carapace.ActionMap{
"color": carapace.ActionValues("always", "never", "auto").StyleF(style.ForKeyword),
"color": git.ActionColorModes(),
"f": carapace.ActionFiles(),
"open-files-in-pager": carapace.Batch(
os.ActionPathExecutables(),
Expand Down
3 changes: 1 addition & 2 deletions completers/git_completer/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/rsteube/carapace-bin/pkg/actions/time"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace-bin/pkg/util"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -213,7 +212,7 @@ func init() {
"after": time.ActionDate(),
"author": git.ActionAuthors(),
"before": time.ActionDate(),
"color": carapace.ActionValues("always", "never", "auto").StyleF(style.ForKeyword),
"color": git.ActionColorModes(),
"color-moved": carapace.ActionValuesDescribed(
"no", "Moved lines are not highlighted",
"default", "Is a synonym for zebra",
Expand Down
3 changes: 1 addition & 2 deletions completers/git_completer/cmd/showBranch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +38,7 @@ func init() {
showBranchCmd.Flag("reflog").NoOptDefVal = " "

carapace.Gen(showBranchCmd).FlagCompletion(carapace.ActionMap{
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"color": git.ActionColorModes(),
"reflog": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 1:
Expand Down
3 changes: 1 addition & 2 deletions completers/git_completer/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/os"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -47,7 +46,7 @@ func init() {

carapace.Gen(tagCmd).FlagCompletion(carapace.ActionMap{
"cleanup": git.ActionCleanupMode(),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"color": git.ActionColorModes(),
"contains": git.ActionRefs(git.RefOption{Commits: 100, HeadCommits: 100}),
"file": carapace.ActionFiles(),
"local-user": os.ActionGpgKeyIds(),
Expand Down
14 changes: 14 additions & 0 deletions pkg/actions/tools/git/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package git

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

// ActionColorModes completes color modes
//
// always
// auto
func ActionColorModes() carapace.Action {
return carapace.ActionValues("always", "auto", "never").StyleF(style.ForKeyword)
}
73 changes: 73 additions & 0 deletions pkg/actions/tools/git/diff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package git

import "github.com/rsteube/carapace"

// ActionDiffAlgorithms completes diff algorithms.
//
// myers (The basic greedy diff algorithm)
// minimal (Spend extra time to make sure the smallest possible diff is produced)
func ActionDiffAlgorithms() carapace.Action {
return carapace.ActionValuesDescribed(
"myers", "The basic greedy diff algorithm",
"minimal", "Spend extra time to make sure the smallest possible diff is produced",
"patience", "Use patience diff algorithm when generating patches",
"histogram", "This algorithm extends the patience algorithm to support low-occurrence common elements",
)
}

// ActionColorMovedModes completes color moved modes.
//
// no (Moved lines are not highlighted)
// default (default mode)
func ActionColorMovedModes() carapace.Action {
return carapace.ActionValuesDescribed(
"no", "Moved lines are not highlighted",
"default", "default mode",
"plain", "plain mode",
"blocks", "greedily detects blocks",
"zebra", "Blocks of moved text are detected as in blocks mode",
"dimmed-zebra", "Similar to zebra, but additional dimming of uninteresting parts of moved code",
)
}

// ActionColorMovedWsModes completed color moded whitespace modes.
//
// no (Do not ignore whitespace when performing move detection)
// ignore-space-at-eol (Ignore changes in whitespace at EOL)
func ActionColorMovedWsModes() carapace.Action {
return carapace.ActionValuesDescribed(
"no", "Do not ignore whitespace when performing move detection",
"ignore-space-at-eol", "Ignore changes in whitespace at EOL",
"ignore-space-change", "Ignore changes in amount of whitespace.",
"ignore-all-space", "Ignore whitespace when comparing lines.",
"allow-indentation-change", "Initially ignore any whitespace in the move detection",
)
}

// ActionWordDiffModes completes word diff modes.
//
// no (Do not ignore whitespace when performing move detection)
// ignore-space-at-eol (Ignore changes in whitespace at EOL)
func ActionWordDiffModes() carapace.Action {
return carapace.ActionValuesDescribed(
"color", "Highlight changed words using only colors",
"plain", "Show words as [-removed-] and {+added+}",
"porcelain", "Use a special line-based format intended for script consumption",
"none", "Disable word diff again",
)
}

// ActionWsErrorHighlightModes completes whitespace error highlight modes.
//
// context (context lines)
// old (old lines)
func ActionWsErrorHighlightModes() carapace.Action {
return carapace.ActionValuesDescribed(
"context", "context lines",
"old", "old lines",
"new", "new linex",
"none", "reset previous values",
"default", "reset to new",
"all", "shorthand for old,new,context",
)
}

0 comments on commit 003af01

Please sign in to comment.