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