Skip to content

Commit

Permalink
Merge pull request #2271 from rsteube/git-move-common-flags
Browse files Browse the repository at this point in the history
git: moved common flags
  • Loading branch information
rsteube authored Feb 24, 2024
2 parents c5da6f9 + 837a84e commit 3fbff7f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 109 deletions.
112 changes: 112 additions & 0 deletions completers/git_completer/cmd/common/diff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package common

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

func AddDiffFlags(cmd *cobra.Command) {
cmd.Flags().BoolS("0", "0", false, "Omit diff output for unmerged entries")
cmd.Flags().StringS("O", "O", "", "Control the order in which files appear in the output")
cmd.Flags().BoolS("R", "R", false, "Swap two inputs")
cmd.Flags().StringS("S", "S", "", "Look for differences that change the number of occurrences of the specified string")
cmd.Flags().String("abbrev", "", "show only a partial prefix")
cmd.Flags().String("anchored", "", "Generate a diff using the \"anchored diff\" algorithm")
cmd.Flags().BoolP("base", "1", false, "compare with base")
cmd.Flags().Bool("binary", false, "output a binary diff")
cmd.Flags().StringP("break-rewrites", "B", "", "Break complete rewrite changes into pairs of delete and create")
cmd.Flags().Bool("cached", false, "View the changes you staged in the index/cache")
cmd.Flags().Bool("check", false, "Warn if changes introduce conflict markers or whitespace errors")
cmd.Flags().String("color", "", "Show colored diff")
cmd.Flags().String("color-moved", "", "Moved lines of code are colored differently")
cmd.Flags().String("color-moved-ws", "", "This configures how whitespace is ignored when performing the move detection")
cmd.Flags().String("color-words", "", "Equivalent to --word-diff=color plus (if a regex was specified)")
cmd.Flags().Bool("compact-summary", false, "Output a condensed summary of extended header information")
cmd.Flags().Bool("cumulative", false, "Synonym for --dirstat=cumulative")
cmd.Flags().String("diff-algorithm", "", "")
cmd.Flags().String("diff-filter", "", "filter files")
cmd.Flags().StringP("dirstat", "X", "", "Output the distribution of relative amount of changes for each sub-directory")
cmd.Flags().String("dirstat-by-file", "", "Synonym for --dirstat=files,param1,param2...")
cmd.Flags().String("dst-prefix", "", "Show the given destination prefix instead of \"b/\"")
cmd.Flags().Bool("exit-code", false, "Make the program exit with codes similar to diff(1)")
cmd.Flags().Bool("ext-diff", false, "Allow an external diff helper to be executed")
cmd.Flags().StringP("find-copies", "C", "", "Detect copies as well as renames")
cmd.Flags().Bool("find-copies-harder", false, "inspect unmodified files as candidates for the source of copy")
cmd.Flags().String("find-object", "", "Look for differences that change the number of occurrences of the specified object")
cmd.Flags().StringP("find-renames", "M", "", "Detect renames")
cmd.Flags().Bool("full-index", false, "show the full pre- and post-image blob object names")
cmd.Flags().BoolP("function-context", "W", false, "Show whole surrounding functions of changes")
cmd.Flags().Bool("histogram", false, "Generate a diff using the \"histogram diff\" algorithm")
cmd.Flags().BoolP("ignore-all-space", "w", false, "Ignore whitespace when comparing lines")
cmd.Flags().Bool("ignore-blank-lines", false, "Ignore changes whose lines are all blank")
cmd.Flags().Bool("ignore-cr-at-eol", false, "Ignore carriage-return at the end of line when doing a comparison")
cmd.Flags().Bool("ignore-space-at-eol", false, "Ignore changes in whitespace at EOL")
cmd.Flags().BoolP("ignore-space-change", "b", false, "Ignore changes in amount of whitespace")
cmd.Flags().String("ignore-submodules", "", "Ignore changes to submodules in the diff generation")
cmd.Flags().Bool("indent-heuristic", false, "Enable the heuristic that shifts diff hunk boundaries to make patches easier to read")
cmd.Flags().String("inter-hunk-context", "", "Show the context between diff hunks")
cmd.Flags().BoolP("irreversible-delete", "D", false, "Omit the preimage for deletes")
cmd.Flags().Bool("ita-invisible-in-index", false, "this option makes the entry appear as a new file")
cmd.Flags().StringS("l", "l", "", "prevent rename/copy detection from running if the number of rename/copy targets exceeds the specified number")
cmd.Flags().String("line-prefix", "", "Prepend an additional prefix to every line of output")
cmd.Flags().Bool("minimal", false, "Spend extra time to make sure the smallest possible diff is produced")
cmd.Flags().Bool("name-only", false, "Show only names of changed files")
cmd.Flags().Bool("name-status", false, "Show only names and status of changed files")
cmd.Flags().Bool("no-color", false, "Turn off colored diff")
cmd.Flags().Bool("no-color-moved", false, "Turn off move detection")
cmd.Flags().Bool("no-color-moved-ws", false, "Do not ignore whitespace when performing move detection")
cmd.Flags().Bool("no-ext-diff", false, "Disallow external diff drivers")
cmd.Flags().Bool("no-indent-heuristic", false, "Disable the indent heuristic")
cmd.Flags().Bool("no-index", false, "Compare paths on the file system")
cmd.Flags().BoolP("no-patch", "s", false, "Suppress diff output")
cmd.Flags().Bool("no-prefix", false, "Do not show any source or destination prefix")
cmd.Flags().Bool("no-rename-empty", false, "Whether to use empty blobs as rename source")
cmd.Flags().Bool("no-renames", false, "Turn off rename detection")
cmd.Flags().Bool("numstat", false, "Similar to --stat, but shows number of added and deleted lines in decimal notation")
cmd.Flags().BoolP("ours", "2", false, "compare with our branch")
cmd.Flags().String("output", "", "Output to a specific file instead of stdout")
cmd.Flags().String("output-indicator-context", "", "Specify the character used to indicate context lines in the generated patch")
cmd.Flags().String("output-indicator-new", "", "Specify the character used to indicate new lines in the generated patch")
cmd.Flags().String("output-indicator-old", "", "Specify the character used to indicate old lines in the generated patch")
cmd.Flags().BoolP("patch", "p", false, "Generate patch")
cmd.Flags().Bool("patch-with-raw", false, "Synonym for -p --raw")
cmd.Flags().Bool("patch-with-stat", false, "Synonym for -p --stat")
cmd.Flags().Bool("patience", false, "Generate a diff using the \"patience diff\" algorithm")
cmd.Flags().Bool("pickaxe-all", false, "When -S or -G finds a change, show all the changes in that changeset")
cmd.Flags().Bool("pickaxe-regex", false, "Treat the <string> given to -S as an extended POSIX regular expression to match")
cmd.Flags().Bool("quiet", false, "Disable all output of the program")
cmd.Flags().Bool("raw", false, "Generate the diff in raw format")
cmd.Flags().String("relative,", "", "exclude changes outside the directory")
cmd.Flags().Bool("rename-empty", false, "Whether to use empty blobs as rename source")
cmd.Flags().Bool("shortstat", false, "Output only the last line of the --stat format")
cmd.Flags().String("src-prefix", "", "Show the given source prefix instead of \"a/\"")
cmd.Flags().String("stat", "", "")
cmd.Flags().String("submodule", "", "Specify how differences in submodules are shown")
cmd.Flags().Bool("summary", false, "Output a condensed summary of extended header information")
cmd.Flags().BoolP("text", "a", false, "Treat all files as text")
cmd.Flags().String("textconv", "", "Allow (or disallow) external text conversion filters to be run when comparing binary files")
cmd.Flags().BoolP("theirs", "3", false, "compare with their branch")
cmd.Flags().BoolS("u", "u", false, "Generate patch")
cmd.Flags().StringP("unified", "U", "", "Generate diffs with <n> lines of context instead of the usual three")
cmd.Flags().String("word-diff", "", "Show a word diff, using the <mode> to delimit changed words")
cmd.Flags().String("word-diff-regex", "", "Use <regex> to decide what a word is")
cmd.Flags().String("ws-error-highlight", "", "Highlight whitespace errors in the context, old or new lines of the diff")
cmd.Flags().BoolS("z", "z", false, "do not munge pathnames and use NULs as output field terminators")

cmd.Flag("color-moved").NoOptDefVal = "default"
cmd.Flag("color-moved-ws").NoOptDefVal = " "
cmd.Flag("word-diff").NoOptDefVal = "plain"

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"color": git.ActionColorModes(),
"color-moved": git.ActionColorMovedModes(),
"color-moved-ws": git.ActionColorMovedWsModes(),
"diff-algorithm": git.ActionDiffAlgorithms(),
"ignore-submodules": carapace.ActionValues("none", "untracked", "dirty", "all"),
"output": carapace.ActionFiles(),
"submodule": carapace.ActionValues("short", "long", "log"),
"word-diff": git.ActionWordDiffModes(),
"ws-error-highlight": git.ActionWsErrorHighlightModes().UniqueList(","),
})
}
108 changes: 2 additions & 106 deletions completers/git_completer/cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/common"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
Expand All @@ -19,7 +20,7 @@ var diffCmd = &cobra.Command{
func init() {
carapace.Gen(diffCmd).Standalone()

addDiffFlags(diffCmd)
common.AddDiffFlags(diffCmd)
rootCmd.AddCommand(diffCmd)

carapace.Gen(diffCmd).PositionalAnyCompletion(
Expand All @@ -31,111 +32,6 @@ func init() {
)
}

func addDiffFlags(cmd *cobra.Command) {
cmd.Flags().BoolS("0", "0", false, "Omit diff output for unmerged entries")
cmd.Flags().StringS("O", "O", "", "Control the order in which files appear in the output")
cmd.Flags().BoolS("R", "R", false, "Swap two inputs")
cmd.Flags().StringS("S", "S", "", "Look for differences that change the number of occurrences of the specified string")
cmd.Flags().String("abbrev", "", "show only a partial prefix")
cmd.Flags().String("anchored", "", "Generate a diff using the \"anchored diff\" algorithm")
cmd.Flags().BoolP("base", "1", false, "compare with base")
cmd.Flags().Bool("binary", false, "output a binary diff")
cmd.Flags().StringP("break-rewrites", "B", "", "Break complete rewrite changes into pairs of delete and create")
cmd.Flags().Bool("cached", false, "View the changes you staged in the index/cache")
cmd.Flags().Bool("check", false, "Warn if changes introduce conflict markers or whitespace errors")
cmd.Flags().String("color", "", "Show colored diff")
cmd.Flags().String("color-moved", "", "Moved lines of code are colored differently")
cmd.Flags().String("color-moved-ws", "", "This configures how whitespace is ignored when performing the move detection")
cmd.Flags().String("color-words", "", "Equivalent to --word-diff=color plus (if a regex was specified)")
cmd.Flags().Bool("compact-summary", false, "Output a condensed summary of extended header information")
cmd.Flags().Bool("cumulative", false, "Synonym for --dirstat=cumulative")
cmd.Flags().String("diff-algorithm", "", "")
cmd.Flags().String("diff-filter", "", "filter files")
cmd.Flags().StringP("dirstat", "X", "", "Output the distribution of relative amount of changes for each sub-directory")
cmd.Flags().String("dirstat-by-file", "", "Synonym for --dirstat=files,param1,param2...")
cmd.Flags().String("dst-prefix", "", "Show the given destination prefix instead of \"b/\"")
cmd.Flags().Bool("exit-code", false, "Make the program exit with codes similar to diff(1)")
cmd.Flags().Bool("ext-diff", false, "Allow an external diff helper to be executed")
cmd.Flags().StringP("find-copies", "C", "", "Detect copies as well as renames")
cmd.Flags().Bool("find-copies-harder", false, "inspect unmodified files as candidates for the source of copy")
cmd.Flags().String("find-object", "", "Look for differences that change the number of occurrences of the specified object")
cmd.Flags().StringP("find-renames", "M", "", "Detect renames")
cmd.Flags().Bool("full-index", false, "show the full pre- and post-image blob object names")
cmd.Flags().BoolP("function-context", "W", false, "Show whole surrounding functions of changes")
cmd.Flags().Bool("histogram", false, "Generate a diff using the \"histogram diff\" algorithm")
cmd.Flags().BoolP("ignore-all-space", "w", false, "Ignore whitespace when comparing lines")
cmd.Flags().Bool("ignore-blank-lines", false, "Ignore changes whose lines are all blank")
cmd.Flags().Bool("ignore-cr-at-eol", false, "Ignore carriage-return at the end of line when doing a comparison")
cmd.Flags().Bool("ignore-space-at-eol", false, "Ignore changes in whitespace at EOL")
cmd.Flags().BoolP("ignore-space-change", "b", false, "Ignore changes in amount of whitespace")
cmd.Flags().String("ignore-submodules", "", "Ignore changes to submodules in the diff generation")
cmd.Flags().Bool("indent-heuristic", false, "Enable the heuristic that shifts diff hunk boundaries to make patches easier to read")
cmd.Flags().String("inter-hunk-context", "", "Show the context between diff hunks")
cmd.Flags().BoolP("irreversible-delete", "D", false, "Omit the preimage for deletes")
cmd.Flags().Bool("ita-invisible-in-index", false, "this option makes the entry appear as a new file")
cmd.Flags().StringS("l", "l", "", "prevent rename/copy detection from running if the number of rename/copy targets exceeds the specified number")
cmd.Flags().String("line-prefix", "", "Prepend an additional prefix to every line of output")
cmd.Flags().Bool("minimal", false, "Spend extra time to make sure the smallest possible diff is produced")
cmd.Flags().Bool("name-only", false, "Show only names of changed files")
cmd.Flags().Bool("name-status", false, "Show only names and status of changed files")
cmd.Flags().Bool("no-color", false, "Turn off colored diff")
cmd.Flags().Bool("no-color-moved", false, "Turn off move detection")
cmd.Flags().Bool("no-color-moved-ws", false, "Do not ignore whitespace when performing move detection")
cmd.Flags().Bool("no-ext-diff", false, "Disallow external diff drivers")
cmd.Flags().Bool("no-indent-heuristic", false, "Disable the indent heuristic")
cmd.Flags().Bool("no-index", false, "Compare paths on the file system")
cmd.Flags().BoolP("no-patch", "s", false, "Suppress diff output")
cmd.Flags().Bool("no-prefix", false, "Do not show any source or destination prefix")
cmd.Flags().Bool("no-rename-empty", false, "Whether to use empty blobs as rename source")
cmd.Flags().Bool("no-renames", false, "Turn off rename detection")
cmd.Flags().Bool("numstat", false, "Similar to --stat, but shows number of added and deleted lines in decimal notation")
cmd.Flags().BoolP("ours", "2", false, "compare with our branch")
cmd.Flags().String("output", "", "Output to a specific file instead of stdout")
cmd.Flags().String("output-indicator-context", "", "Specify the character used to indicate context lines in the generated patch")
cmd.Flags().String("output-indicator-new", "", "Specify the character used to indicate new lines in the generated patch")
cmd.Flags().String("output-indicator-old", "", "Specify the character used to indicate old lines in the generated patch")
cmd.Flags().BoolP("patch", "p", false, "Generate patch")
cmd.Flags().Bool("patch-with-raw", false, "Synonym for -p --raw")
cmd.Flags().Bool("patch-with-stat", false, "Synonym for -p --stat")
cmd.Flags().Bool("patience", false, "Generate a diff using the \"patience diff\" algorithm")
cmd.Flags().Bool("pickaxe-all", false, "When -S or -G finds a change, show all the changes in that changeset")
cmd.Flags().Bool("pickaxe-regex", false, "Treat the <string> given to -S as an extended POSIX regular expression to match")
cmd.Flags().Bool("quiet", false, "Disable all output of the program")
cmd.Flags().Bool("raw", false, "Generate the diff in raw format")
cmd.Flags().String("relative,", "", "exclude changes outside the directory")
cmd.Flags().Bool("rename-empty", false, "Whether to use empty blobs as rename source")
cmd.Flags().Bool("shortstat", false, "Output only the last line of the --stat format")
cmd.Flags().String("src-prefix", "", "Show the given source prefix instead of \"a/\"")
cmd.Flags().String("stat", "", "")
cmd.Flags().String("submodule", "", "Specify how differences in submodules are shown")
cmd.Flags().Bool("summary", false, "Output a condensed summary of extended header information")
cmd.Flags().BoolP("text", "a", false, "Treat all files as text")
cmd.Flags().String("textconv", "", "Allow (or disallow) external text conversion filters to be run when comparing binary files")
cmd.Flags().BoolP("theirs", "3", false, "compare with their branch")
cmd.Flags().BoolS("u", "u", false, "Generate patch")
cmd.Flags().StringP("unified", "U", "", "Generate diffs with <n> lines of context instead of the usual three")
cmd.Flags().String("word-diff", "", "Show a word diff, using the <mode> to delimit changed words")
cmd.Flags().String("word-diff-regex", "", "Use <regex> to decide what a word is")
cmd.Flags().String("ws-error-highlight", "", "Highlight whitespace errors in the context, old or new lines of the diff")
cmd.Flags().BoolS("z", "z", false, "do not munge pathnames and use NULs as output field terminators")

cmd.Flag("color-moved").NoOptDefVal = "default"
cmd.Flag("color-moved-ws").NoOptDefVal = " "
cmd.Flag("word-diff").NoOptDefVal = "plain"

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"color": git.ActionColorModes(),
"color-moved": git.ActionColorMovedModes(),
"color-moved-ws": git.ActionColorMovedWsModes(),
"diff-algorithm": git.ActionDiffAlgorithms(),
"ignore-submodules": carapace.ActionValues("none", "untracked", "dirty", "all"),
"output": carapace.ActionFiles(),
"submodule": carapace.ActionValues("short", "long", "log"),
"word-diff": git.ActionWordDiffModes(),
"ws-error-highlight": git.ActionWsErrorHighlightModes().UniqueList(","),
})
}

func actionDiffArgs(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if cmd.Flag("no-index").Changed {
Expand Down
3 changes: 2 additions & 1 deletion completers/git_completer/cmd/difftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/common"
"github.com/spf13/cobra"
)

Expand All @@ -24,7 +25,7 @@ func init() {
difftoolCmd.Flags().Bool("tool-help", false, "print a list of diff tools that may be used with `--tool`")
difftoolCmd.Flags().Bool("trust-exit-code", false, "exit when an invoked diff tool returns a non - zero exit code")

addDiffFlags(difftoolCmd)
common.AddDiffFlags(difftoolCmd)
rootCmd.AddCommand(difftoolCmd)

carapace.Gen(difftoolCmd).FlagCompletion(carapace.ActionMap{
Expand Down
3 changes: 2 additions & 1 deletion completers/git_completer/cmd/rangeDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/common"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)
Expand All @@ -22,7 +23,7 @@ func init() {
rangeDiffCmd.Flags().Bool("no-dual-color", false, "Do not recreate the original diffs’ coloring")
rangeDiffCmd.Flags().String("no-notes", "", "This flag is passed to the git log progeram")
rangeDiffCmd.Flags().String("notes", "", "This flag is passed to the git log program")
addDiffFlags(rangeDiffCmd)
common.AddDiffFlags(rangeDiffCmd)
rootCmd.AddCommand(rangeDiffCmd)

rangeDiffCmd.Flag("no-notes").NoOptDefVal = " "
Expand Down
3 changes: 2 additions & 1 deletion completers/git_completer/cmd/stash_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/common"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)
Expand All @@ -16,7 +17,7 @@ func init() {
carapace.Gen(stash_showCmd).Standalone()
stash_showCmd.Flags().Bool("include-untracked", false, "include untracked")
stash_showCmd.Flags().Bool("only-untracked", false, "only untracked")
addDiffFlags(stash_showCmd)
common.AddDiffFlags(stash_showCmd)

stashCmd.AddCommand(stash_showCmd)

Expand Down

0 comments on commit 3fbff7f

Please sign in to comment.