Skip to content

Commit

Permalink
spec: default arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 10, 2022
1 parent a9554ed commit ea0bfeb
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 57 deletions.
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
})

carapace.Gen(archiveCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(archiveCmd).PositionalAnyCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bisect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
if len(c.Parts) > 2 {
return carapace.ActionValues()
}
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bisect_bad.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
bisectCmd.AddCommand(bisect_badCmd)

carapace.Gen(bisect_badCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bisect_good.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
bisectCmd.AddCommand(bisect_goodCmd)

carapace.Gen(bisect_goodCmd).PositionalAnyCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bisect_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
bisectCmd.AddCommand(bisect_resetCmd)

carapace.Gen(bisect_resetCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bisect_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
if bisect_startCmd.Flags().ArgsLenAtDash() != -1 {
return carapace.ActionFiles()
}
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
)
}
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
carapace.Gen(blameCmd).FlagCompletion(carapace.ActionMap{
"S": carapace.ActionFiles(),
"contents": carapace.ActionFiles(),
"ignore-rev": git.ActionRefs(git.RefOptionDefault),
"ignore-rev": git.ActionRefs(git.RefOption{}.Default()),
"ignore-revs-file": carapace.ActionFiles(),
})

Expand All @@ -63,7 +63,7 @@ func init() {
if util.HasPathPrefix(c.CallbackValue) {
return carapace.ActionFiles()
}
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.Args[0]) {
Expand Down
10 changes: 5 additions & 5 deletions completers/git_completer/cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func init() {
rootCmd.AddCommand(branchCmd)

carapace.Gen(branchCmd).FlagCompletion(carapace.ActionMap{
"D": git.ActionRefs(git.RefOptionDefault),
"D": git.ActionRefs(git.RefOption{}.Default()),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"contains": git.ActionRefs(git.RefOptionDefault),
"contains": git.ActionRefs(git.RefOption{}.Default()),
"delete": git.ActionRefs(git.RefOption{LocalBranches: true, RemoteBranches: true}),
"merged": git.ActionRefs(git.RefOptionDefault),
"no-contains": git.ActionRefs(git.RefOptionDefault),
"no-merged": git.ActionRefs(git.RefOptionDefault),
"merged": git.ActionRefs(git.RefOption{}.Default()),
"no-contains": git.ActionRefs(git.RefOption{}.Default()),
"no-merged": git.ActionRefs(git.RefOption{}.Default()),
"points-at": git.ActionRefs(git.RefOption{RemoteBranches: true, Tags: true}),
"set-upstream-to": git.ActionRefs(git.RefOption{RemoteBranches: true, Tags: true}),
"sort": git.ActionFieldNames(),
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/bundle_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ func init() {
)

carapace.Gen(bundle_createCmd).PositionalAnyCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/catFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func init() {
// TODO completions
carapace.Gen(catFileCmd).PositionalCompletion(
carapace.ActionValues("blob", "tree", "commit", "tag"),
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
})

carapace.Gen(checkoutCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(checkoutCmd).PositionalAnyCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/cherryPick.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
// TODO `...` divider not yet working
carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
if len(c.Parts) < 2 {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}
return carapace.ActionValues()
}),
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/clangFormat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {
}

if diff := clangFormatCmd.Flag("diff").Changed; len(c.Args) == 0 || (len(c.Args) == 1 && diff) {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}
return carapace.ActionFiles()
}),
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
if describeCmd.Flag("dirty").Changed || describeCmd.Flag("broken").Changed {
return carapace.ActionValues()
} else {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}
}),
)
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
if diffCmd.Flags().ArgsLenAtDash() != -1 {
return carapace.ActionFiles()
}
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
)
}
Expand Down
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/difftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func init() {
})

carapace.Gen(difftoolCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(difftoolCmd).DashAnyCompletion(
Expand Down
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/formatPatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func init() {
carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
case 1:
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
default:
return carapace.ActionValues()
}
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func init() {
)

carapace.Gen(grepCmd).PositionalAnyCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(grepCmd).DashAnyCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/gui_blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
if util.HasPathPrefix(c.CallbackValue) {
return carapace.ActionFiles()
}
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
carapace.ActionFiles(),
)
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/gui_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
guiCmd.AddCommand(browserCmd)

carapace.Gen(browserCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
} else {
return carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
if len(c.Parts) < 2 {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
} else {
return carapace.ActionValues()
}
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func init() {

carapace.Gen(mergeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return git.ActionRefs(git.RefOptionDefault).Invoke(c).Filter(c.Args).ToA()
return git.ActionRefs(git.RefOption{}.Default()).Invoke(c).Filter(c.Args).ToA()
}),
)
}
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func init() {
carapace.Gen(rebaseCmd).FlagCompletion(carapace.ActionMap{
"empty": carapace.ActionValues("drop", "keep", "ask"),
"gpg-sign": os.ActionGpgKeyIds(),
"onto": git.ActionRefs(git.RefOptionDefault),
"onto": git.ActionRefs(git.RefOption{}.Default()),
"rebase-merges": carapace.ActionValues("rebase-cousins", "no-rebase-cousins"),
"strategy": git.ActionMergeStrategy(),
"strategy-option": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
Expand All @@ -75,7 +75,7 @@ func init() {
!rebaseCmd.Flag("abort").Changed &&
!rebaseCmd.Flag("skip").Changed &&
!rebaseCmd.Flag("edit-todo").Changed {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
} else {
return carapace.ActionValues()
}
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
})

carapace.Gen(resetCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(resetCmd).PositionalAnyCompletion(
Expand Down
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func init() {
carapace.Gen(restoreCmd).FlagCompletion(carapace.ActionMap{
"conflict": carapace.ActionValues("merge", "diff3"),
"pathspec-from-file": carapace.ActionFiles(),
"recurse-submodules": git.ActionRefs(git.RefOptionDefault),
"source": git.ActionRefs(git.RefOptionDefault),
"recurse-submodules": git.ActionRefs(git.RefOption{}.Default()),
"source": git.ActionRefs(git.RefOption{}.Default()),
})

carapace.Gen(restoreCmd).PositionalAnyCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func init() {
}),
})

carapace.Gen(revertCmd).PositionalAnyCompletion(git.ActionRefs(git.RefOptionDefault))
carapace.Gen(revertCmd).PositionalAnyCompletion(git.ActionRefs(git.RefOption{}.Default()))
}
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/shortlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func init() {
} else {
return carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
if len(c.Parts) < 2 {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
} else {
return carapace.ActionValues()
}
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
case 1:
return git.ActionRefFiles(c.Parts[0])
default:
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/submodule_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
submoduleCmd.AddCommand(submodule_summaryCmd)

carapace.Gen(submodule_summaryCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault), // TODO commmit of submodule??
git.ActionRefs(git.RefOption{}.Default()), // TODO commmit of submodule??
)

carapace.Gen(submodule_summaryCmd).PositionalAnyCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/whatchanged.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
} else {
return carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
if len(c.Parts) < 2 {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
} else {
return carapace.ActionValues()
}
Expand Down
4 changes: 2 additions & 2 deletions completers/gitk_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func init() {

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"argscmd": carapace.ActionFiles(),
"select-commit": git.ActionRefs(git.RefOptionDefault),
"select-commit": git.ActionRefs(git.RefOption{}.Default()),
"since": time.ActionDate(),
"until": time.ActionDate(),
})

carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionMultiParts("...", func(c carapace.Context) carapace.Action {
return git.ActionRefs(git.RefOptionDefault)
return git.ActionRefs(git.RefOption{}.Default())
}),
)

Expand Down
2 changes: 1 addition & 1 deletion completers/tig_completer/cmd/reflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
rootCmd.AddCommand(reflogCmd)

carapace.Gen(reflogCmd).PositionalAnyCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)
}
2 changes: 1 addition & 1 deletion completers/tig_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
})

carapace.Gen(rootCmd).PositionalCompletion(
git.ActionRefs(git.RefOptionDefault),
git.ActionRefs(git.RefOption{}.Default()),
)

carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/mitchellh/go-ps v1.0.0
github.com/pelletier/go-toml v1.9.5
github.com/rsteube/carapace v0.20.2
github.com/rsteube/carapace-spec v0.0.16
github.com/rsteube/carapace-spec v0.0.17
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rsteube/carapace v0.20.2 h1:i6QSQZ5vZKmXcwupsYch8XdJ/GBbZU+H8XtfXEs8Z4E=
github.com/rsteube/carapace v0.20.2/go.mod h1:GgiwpPVhucHNOv0AmtIkxhiEFkCMP5BBRauyQLP0mFY=
github.com/rsteube/carapace-spec v0.0.16 h1:HW3+VYX1ZyT9QDUFtjdgCX2dVYAiZL9d0I00qocW478=
github.com/rsteube/carapace-spec v0.0.16/go.mod h1:vyKkMfbIYHhPiUeyCemLWh96XNPwWI9B6Go0+W5nDUw=
github.com/rsteube/carapace-spec v0.0.17 h1:rLV3fSZyqPgwCl8I3taOamMsINUUgtZ18ggLAroTzLI=
github.com/rsteube/carapace-spec v0.0.17/go.mod h1:vyKkMfbIYHhPiUeyCemLWh96XNPwWI9B6Go0+W5nDUw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
Expand Down
19 changes: 8 additions & 11 deletions pkg/actions/tools/git/action.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package git

import (
"reflect"
"strings"

"github.com/rsteube/carapace"
Expand All @@ -24,23 +23,21 @@ type RefOption struct {
Stashes bool
}

var RefOptionDefault = RefOption{
LocalBranches: true,
RemoteBranches: true,
Commits: 100,
Tags: true,
Stashes: true,
func (o RefOption) Default() RefOption {
o.LocalBranches = true
o.RemoteBranches = true
o.Commits = 100
o.Tags = true
o.Stashes = true
return o

}

// ActionRefs completes git references (commits, branches, tags)
// HEAD~1 (last commit msg)
// v0.0.1 (last commit msg)
func ActionRefs(refOption RefOption) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if reflect.DeepEqual(refOption, RefOption{}) { // for macros: if none is set use the default
refOption = RefOptionDefault
}

vals := make([]string, 0)
if branches, err := branches(c, refOption); err != nil {
return carapace.ActionMessage(err.Error())
Expand Down

0 comments on commit ea0bfeb

Please sign in to comment.