Skip to content

Commit

Permalink
Merge pull request #1146 from rsteube/git-changes-default
Browse files Browse the repository at this point in the history
git: ActionChanges default
  • Loading branch information
rsteube authored May 17, 2022
2 parents a96f3fd + 05af3f1 commit 093a700
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion completers/git_completer/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {

carapace.Gen(addCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return git.ActionChanges(git.ChangeOption{Unstaged: true}).Invoke(c).Filter(c.Args).ToA()
return git.ActionChanges(git.ChangeOpts{Unstaged: true}).Invoke(c).Filter(c.Args).ToA()
}),
)
}
4 changes: 2 additions & 2 deletions completers/git_completer/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func init() {
carapace.Gen(restoreCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if restoreCmd.Flag("staged").Changed {
return git.ActionChanges(git.ChangeOption{Staged: true})
return git.ActionChanges(git.ChangeOpts{Staged: true})
}
return git.ActionChanges(git.ChangeOption{Unstaged: true})
return git.ActionChanges(git.ChangeOpts{Unstaged: true})
}),
)
}
10 changes: 8 additions & 2 deletions pkg/actions/tools/git/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import (
"github.com/rsteube/carapace/pkg/style"
)

type ChangeOption struct {
type ChangeOpts struct {
Staged bool
Unstaged bool
}

func (o ChangeOpts) Default() ChangeOpts {
o.Staged = true
o.Unstaged = true
return o
}

// ActionChanges completes (un)staged changes
// fileA ( M)
// pathA/fileB (??)
func ActionChanges(opts ChangeOption) carapace.Action {
func ActionChanges(opts ChangeOpts) carapace.Action {
// TODO multiparts action to complete step by step
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("git", "status", "--porcelain")(func(output []byte) carapace.Action {
Expand Down

0 comments on commit 093a700

Please sign in to comment.