1package repo
2
3import (
4 "github.com/charmbracelet/soft-serve/cmd"
5 "github.com/charmbracelet/soft-serve/pkg/access"
6 "github.com/charmbracelet/soft-serve/pkg/backend"
7 "github.com/spf13/cobra"
8)
9
10// listCommand returns a command that list file or directory at path.
11func listCommand() *cobra.Command {
12 var all bool
13
14 listCmd := &cobra.Command{
15 Use: "list",
16 Aliases: []string{"ls"},
17 Short: "List repositories",
18 Args: cobra.NoArgs,
19 RunE: func(co *cobra.Command, _ []string) error {
20 ctx := co.Context()
21 be := backend.FromContext(ctx)
22 repos, err := be.Repositories(ctx)
23 if err != nil {
24 return err
25 }
26
27 for _, r := range repos {
28 if !cmd.CheckUserHasAccess(co, r.Name(), access.ReadOnlyAccess) {
29 continue
30 }
31
32 if !r.IsHidden() || all {
33 co.Println(r.Name())
34 }
35 }
36 return nil
37 },
38 }
39
40 listCmd.Flags().BoolVarP(&all, "all", "a", false, "List all repositories")
41
42 return listCmd
43}