1package cmd
2
3import (
4 "fmt"
5 "strings"
6
7 "github.com/charmbracelet/soft-serve/server/backend"
8 "github.com/spf13/cobra"
9)
10
11func repoCommand() *cobra.Command {
12 cmd := &cobra.Command{
13 Use: "repo",
14 Aliases: []string{"repos", "repository", "repositories"},
15 Short: "Manage repositories",
16 }
17
18 cmd.AddCommand(
19 blobCommand(),
20 branchCommand(),
21 collabCommand(),
22 commitCommand(),
23 createCommand(),
24 deleteCommand(),
25 descriptionCommand(),
26 hiddenCommand(),
27 importCommand(),
28 listCommand(),
29 mirrorCommand(),
30 privateCommand(),
31 projectName(),
32 renameCommand(),
33 tagCommand(),
34 treeCommand(),
35 )
36
37 cmd.AddCommand(
38 &cobra.Command{
39 Use: "info REPOSITORY",
40 Short: "Get information about a repository",
41 Args: cobra.ExactArgs(1),
42 PersistentPreRunE: checkIfReadable,
43 RunE: func(cmd *cobra.Command, args []string) error {
44 ctx := cmd.Context()
45 be := backend.FromContext(ctx)
46 rn := args[0]
47 rr, err := be.Repository(ctx, rn)
48 if err != nil {
49 return err
50 }
51
52 r, err := rr.Open()
53 if err != nil {
54 return err
55 }
56
57 head, err := r.HEAD()
58 if err != nil {
59 return err
60 }
61
62 branches, _ := r.Branches()
63 tags, _ := r.Tags()
64
65 // project name and description are optional, handle trailing
66 // whitespace to avoid breaking tests.
67 cmd.Println(strings.TrimSpace(fmt.Sprint("Project Name: ", rr.ProjectName())))
68 cmd.Println("Repository:", rr.Name())
69 cmd.Println(strings.TrimSpace(fmt.Sprint("Description: ", rr.Description())))
70 cmd.Println("Private:", rr.IsPrivate())
71 cmd.Println("Hidden:", rr.IsHidden())
72 cmd.Println("Mirror:", rr.IsMirror())
73 cmd.Println("Default Branch:", head.Name().Short())
74 if len(branches) > 0 {
75 cmd.Println("Branches:")
76 for _, b := range branches {
77 cmd.Println(" -", b)
78 }
79 }
80 if len(tags) > 0 {
81 cmd.Println("Tags:")
82 for _, t := range tags {
83 cmd.Println(" -", t)
84 }
85 }
86
87 return nil
88 },
89 },
90 )
91
92 return cmd
93}