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