-
Notifications
You must be signed in to change notification settings - Fork 119
/
list.go
41 lines (36 loc) 路 991 Bytes
/
list.go
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
package cmd
import (
"github.com/charmbracelet/soft-serve/pkg/access"
"github.com/charmbracelet/soft-serve/pkg/backend"
"github.com/charmbracelet/soft-serve/pkg/sshutils"
"github.com/spf13/cobra"
)
// listCommand returns a command that list file or directory at path.
func listCommand() *cobra.Command {
var all bool
listCmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List repositories",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
be := backend.FromContext(ctx)
pk := sshutils.PublicKeyFromContext(ctx)
repos, err := be.Repositories(ctx)
if err != nil {
return err
}
for _, r := range repos {
if be.AccessLevelByPublicKey(ctx, r.Name(), pk) >= access.ReadOnlyAccess {
if !r.IsHidden() || all {
cmd.Println(r.Name())
}
}
}
return nil
},
}
listCmd.Flags().BoolVarP(&all, "all", "a", false, "List all repositories")
return listCmd
}