File: stack_list.go

package info (click to toggle)
glab 1.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,936 kB
  • sloc: sh: 295; makefile: 153; perl: 99; ruby: 68; javascript: 67
file content (52 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package list

import (
	"fmt"

	"github.com/spf13/cobra"
	"gitlab.com/gitlab-org/cli/commands/cmdutils"
	"gitlab.com/gitlab-org/cli/pkg/git"
	"gitlab.com/gitlab-org/cli/pkg/iostreams"
	"gitlab.com/gitlab-org/cli/pkg/text"
)

func NewCmdStackList(f *cmdutils.Factory) *cobra.Command {
	return &cobra.Command{
		Use:     "list",
		Aliases: []string{"ls"},
		Short:   "Lists all entries in the stack. (EXPERIMENTAL.)",
		Long:    "Lists all entries in the stack. To select a different revision, use a command like 'stack move'.\n" + text.ExperimentalString,
		Example: "glab stack list",
		RunE: func(cmd *cobra.Command, args []string) error {
			title, err := git.GetCurrentStackTitle()
			if err != nil {
				return err
			}

			stack, err := git.GatherStackRefs(title)
			if err != nil {
				return err
			}

			currentBranch, err := git.CurrentBranch()
			if err != nil {
				return err
			}

			run(f.IO, stack, currentBranch)
			return nil
		},
	}
}

func run(io *iostreams.IOStreams, stack git.Stack, currentBranch string) {
	c := io.Color()
	for ref := range stack.Iter() {
		if currentBranch == ref.Branch {
			fmt.Fprintf(io.StdOut, "> %s", c.Bold(ref.Branch))
		} else {
			fmt.Fprintf(io.StdOut, "  %s", ref.Branch)
		}
		fmt.Fprintf(io.StdOut, " - %s\n", c.Cyan(ref.Subject()))
	}
}