@@ -2,6 +2,7 @@ package but
22
33import (
44 "net/url"
5+ "strings"
56
67 "github.com/carapace-sh/carapace"
78 "github.com/carapace-sh/carapace-bin/pkg/actions/tools/git"
@@ -29,46 +30,55 @@ func (o CliIdsOpts) Default() CliIdsOpts {
2930// na
3031// c3
3132func ActionCliIds (opts CliIdsOpts ) carapace.Action {
32- return actionStatus (func (status butStatus ) carapace.Action {
33- batch := carapace .Batch ()
33+ return carapace .ActionCallback (func (c carapace.Context ) carapace.Action {
34+ return actionStatus (strings .Contains (c .Value , ":" ), func (status butStatus ) carapace.Action {
35+ batch := carapace .Batch ()
3436
35- if opts .Changes {
36- for _ , unassigned := range status .UnassignedChanges {
37- batch = append (batch , carapace .ActionStyledValuesDescribed (unassigned .CliID , unassigned .Description (), styleForChangeType (unassigned .ChangeType )).UidF (
38- func (s string , uc uid.Context ) (* url.URL , error ) {
39- return git .Uid ("change" )(unassigned .FilePath , uc )
40- }))
41- }
42- }
43-
44- for _ , stack := range status .Stacks {
4537 if opts .Changes {
46- for _ , assigned := range stack . AssignedChanges {
47- batch = append (batch , carapace .ActionStyledValuesDescribed (assigned .CliID , assigned .Description (), styleForChangeType (assigned .ChangeType )).UidF (
38+ for _ , unassigned := range status . UnassignedChanges {
39+ batch = append (batch , carapace .ActionStyledValuesDescribed (unassigned .CliID , unassigned .Description (), styleForChangeType (unassigned .ChangeType )).UidF (
4840 func (s string , uc uid.Context ) (* url.URL , error ) {
49- return git .Uid ("change" )(assigned .FilePath , uc )
41+ return git .Uid ("change" )(unassigned .FilePath , uc )
5042 }))
5143 }
52-
5344 }
54- if opts .Stacks && ! opts .Branches { // TODO stack has the same id as its branch anyway
55- batch = append (batch , carapace .ActionValues (stack .CliID )) // TODO style (details from the corresponding branch)
56- }
57- for _ , branch := range stack .Branches {
58- if opts .Branches {
59- batch = append (batch , carapace .ActionStyledValuesDescribed (branch .CliID , branch .Name , styles .Git .Branch ).UidF (
60- func (s string , uc uid.Context ) (* url.URL , error ) {
61- return git .Uid ("local-branch" )(branch .Name , uc )
62- }))
45+
46+ for _ , stack := range status .Stacks {
47+ if opts .Changes {
48+ for _ , assigned := range stack .AssignedChanges {
49+ batch = append (batch , carapace .ActionStyledValuesDescribed (assigned .CliID , assigned .Description (), styleForChangeType (assigned .ChangeType )).UidF (
50+ func (s string , uc uid.Context ) (* url.URL , error ) {
51+ return git .Uid ("change" )(assigned .FilePath , uc )
52+ }))
53+ }
54+
6355 }
64- for _ , commit := range branch .Commits {
65- batch = append (batch , carapace .ActionValuesDescribed (commit .CliID , commit .Message ).UidF (
66- func (s string , uc uid.Context ) (* url.URL , error ) {
67- return git .Uid ("ref" )(commit .CommitID , uc )
68- }))
56+ if opts .Stacks && ! opts .Branches { // TODO stack has the same id as its branch anyway
57+ batch = append (batch , carapace .ActionValues (stack .CliID )) // TODO style (details from the corresponding branch)
58+ }
59+ for _ , branch := range stack .Branches {
60+ if opts .Branches {
61+ batch = append (batch , carapace .ActionStyledValuesDescribed (branch .CliID , branch .Name , styles .Git .Branch ).UidF (
62+ func (s string , uc uid.Context ) (* url.URL , error ) {
63+ return git .Uid ("local-branch" )(branch .Name , uc )
64+ }))
65+ }
66+ for _ , commit := range branch .Commits {
67+ batch = append (batch , carapace .ActionValuesDescribed (commit .CliID , commit .Message ).UidF (
68+ func (s string , uc uid.Context ) (* url.URL , error ) {
69+ return git .Uid ("ref" )(commit .CommitID , uc )
70+ }))
71+
72+ for _ , committed := range commit .Changes {
73+ batch = append (batch , carapace .ActionStyledValuesDescribed (committed .CliID , committed .Description (), styleForChangeType (committed .ChangeType )).UidF (
74+ func (s string , uc uid.Context ) (* url.URL , error ) {
75+ return git .Uid ("change" )(committed .FilePath , uc )
76+ }))
77+ }
78+ }
6979 }
7080 }
71- }
72- return batch . ToA ( )
73- }). Tag ( "cli ids" )
81+ return batch . ToA (). MultiParts ( ":" )
82+ }). Tag ( "cli ids" )
83+ })
7484}
0 commit comments