GitLabgitlab-org
cli
main
1package commands
3import (
4 "errors"
6 "github.com/MakeNowJust/heredoc/v2"
7 "github.com/spf13/cobra"
8 "github.com/spf13/pflag"
10 "gitlab.com/gitlab-org/cli/internal/cmdutils"
11 aliasCmd "gitlab.com/gitlab-org/cli/internal/commands/alias"
12 apiCmd "gitlab.com/gitlab-org/cli/internal/commands/api"
13 artifactRegistryCmd "gitlab.com/gitlab-org/cli/internal/commands/artifactregistry"
14 attestationCmd "gitlab.com/gitlab-org/cli/internal/commands/attestation"
15 authCmd "gitlab.com/gitlab-org/cli/internal/commands/auth"
16 autoflowCmd "gitlab.com/gitlab-org/cli/internal/commands/autoflow"
17 changelogCmd "gitlab.com/gitlab-org/cli/internal/commands/changelog"
18 pipelineCmd "gitlab.com/gitlab-org/cli/internal/commands/ci"
19 clusterCmd "gitlab.com/gitlab-org/cli/internal/commands/cluster"
20 completionCmd "gitlab.com/gitlab-org/cli/internal/commands/completion"
21 configCmd "gitlab.com/gitlab-org/cli/internal/commands/config"
22 containerRegistryCmd "gitlab.com/gitlab-org/cli/internal/commands/container_registry"
23 deployKeyCmd "gitlab.com/gitlab-org/cli/internal/commands/deploy-key"
24 deployTokenCmd "gitlab.com/gitlab-org/cli/internal/commands/deploy-token"
25 dfCmd "gitlab.com/gitlab-org/cli/internal/commands/df"
26 duoCmd "gitlab.com/gitlab-org/cli/internal/commands/duo"
27 governCmd "gitlab.com/gitlab-org/cli/internal/commands/govern"
28 gpgCmd "gitlab.com/gitlab-org/cli/internal/commands/gpg-key"
29 "gitlab.com/gitlab-org/cli/internal/commands/help"
30 incidentCmd "gitlab.com/gitlab-org/cli/internal/commands/incident"
31 issueCmd "gitlab.com/gitlab-org/cli/internal/commands/issue"
32 iterationCmd "gitlab.com/gitlab-org/cli/internal/commands/iteration"
33 jobCmd "gitlab.com/gitlab-org/cli/internal/commands/job"
34 labelCmd "gitlab.com/gitlab-org/cli/internal/commands/label"
35 milestoneCmd "gitlab.com/gitlab-org/cli/internal/commands/milestone"
36 minderCmd "gitlab.com/gitlab-org/cli/internal/commands/minder"
37 mrCmd "gitlab.com/gitlab-org/cli/internal/commands/mr"
38 opentofuCmd "gitlab.com/gitlab-org/cli/internal/commands/opentofu"
39 orbitCmd "gitlab.com/gitlab-org/cli/internal/commands/orbit"
40 packagesCmd "gitlab.com/gitlab-org/cli/internal/commands/packages"
41 projectCmd "gitlab.com/gitlab-org/cli/internal/commands/project"
42 releaseCmd "gitlab.com/gitlab-org/cli/internal/commands/release"
43 runnerCmd "gitlab.com/gitlab-org/cli/internal/commands/runner"
44 runnerControllerCmd "gitlab.com/gitlab-org/cli/internal/commands/runnercontroller"
45 scheduleCmd "gitlab.com/gitlab-org/cli/internal/commands/schedule"
46 searchCmd "gitlab.com/gitlab-org/cli/internal/commands/search"
47 securefileCmd "gitlab.com/gitlab-org/cli/internal/commands/securefile"
48 securityCmd "gitlab.com/gitlab-org/cli/internal/commands/security"
49 serviceAccountCmd "gitlab.com/gitlab-org/cli/internal/commands/service-account"
50 skillsCmd "gitlab.com/gitlab-org/cli/internal/commands/skills"
51 snippetCmd "gitlab.com/gitlab-org/cli/internal/commands/snippet"
52 sshCmd "gitlab.com/gitlab-org/cli/internal/commands/ssh-key"
53 stackCmd "gitlab.com/gitlab-org/cli/internal/commands/stack"
54 timelogCmd "gitlab.com/gitlab-org/cli/internal/commands/timelog"
55 todoCmd "gitlab.com/gitlab-org/cli/internal/commands/todo"
56 tokenCmd "gitlab.com/gitlab-org/cli/internal/commands/token"
57 updateCmd "gitlab.com/gitlab-org/cli/internal/commands/update"
58 userCmd "gitlab.com/gitlab-org/cli/internal/commands/user"
59 variableCmd "gitlab.com/gitlab-org/cli/internal/commands/variable"
60 versionCmd "gitlab.com/gitlab-org/cli/internal/commands/version"
61 whatsnewCmd "gitlab.com/gitlab-org/cli/internal/commands/whatsnew"
62 workitemsCmd "gitlab.com/gitlab-org/cli/internal/commands/workitems"
63 "gitlab.com/gitlab-org/cli/internal/config/confighelp"
64)
66// NewCmdRoot is the main root/parent command
67func NewCmdRoot(f cmdutils.Factory) *cobra.Command {
68 c := f.IO().Color()
69 rootCmd := &cobra.Command{
70 Use: "glab <command> <subcommand> [flags]",
71 Short: "A GitLab CLI tool.",
72 Long: `GLab is an open source GitLab CLI tool that brings GitLab to your command line.`,
73 SilenceErrors: true,
74 SilenceUsage: true,
75 Annotations: map[string]string{
76 "help:environment": confighelp.EnvironmentHelp(),
77 "help:feedback": heredoc.Docf(`
78 Encountered a bug or want to suggest a feature?
79 Open an issue using '%s'
80 `, c.Bold(c.Yellow("glab issue create -R gitlab-org/cli"))),
81 },
82 }
84 // We deliberately do NOT call rootCmd.SetOut / rootCmd.SetErr here.
85 // Cobra's c.Print() (used for deprecation warnings, "unknown help topic",
86 // usage-on-error, etc.) routes through OutOrStderr, which returns Out when
87 // it is set and falls back to os.Stderr otherwise. Wiring Out to StdOut
88 // pollutes the stdout data channel with diagnostics — see
89 // https://gitlab.com/gitlab-org/cli/-/issues/8371 and
90 // https://github.com/spf13/cobra/issues/1708. Instead, the help and usage
91 // funcs receive the IOStreams explicitly and route their own output.
93 rootCmd.PersistentFlags().BoolP("help", "h", false, "Show help for this command.")
95 rootCmd.SetHelpFunc(func(command *cobra.Command, args []string) {
96 help.RootHelpFunc(f.IO(), command, args)
97 })
98 rootCmd.SetUsageFunc(func(command *cobra.Command) error {
99 return help.RootUsageFunc(f.IO().StdErr, command)
100 })
101 rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
102 if errors.Is(err, pflag.ErrHelp) {
103 return err
104 }
105 return &cmdutils.FlagError{Err: err}
106 })
108 buildInfo := f.BuildInfo()
109 formattedVersion := versionCmd.Scheme(buildInfo.Version, buildInfo.Commit)
110 rootCmd.SetVersionTemplate(formattedVersion)
111 rootCmd.Version = formattedVersion
113 // Child commands
114 rootCmd.AddCommand(aliasCmd.NewCmdAlias(f))
115 rootCmd.AddCommand(configCmd.NewCmdConfig(f))
116 rootCmd.AddCommand(completionCmd.NewCmdCompletion(f.IO()))
117 rootCmd.AddCommand(versionCmd.NewCmdVersion(f))
118 rootCmd.AddCommand(updateCmd.NewCheckUpdateCmd(f))
119 rootCmd.AddCommand(whatsnewCmd.NewCmd(f))
120 rootCmd.AddCommand(authCmd.NewCmdAuth(f))
122 rootCmd.AddCommand(apiCmd.NewCmdApi(f, nil))
123 rootCmd.AddCommand(artifactRegistryCmd.NewCmd(f))
124 rootCmd.AddCommand(autoflowCmd.NewCmd(f))
125 rootCmd.AddCommand(changelogCmd.NewCmdChangelog(f))
126 rootCmd.AddCommand(clusterCmd.NewCmdCluster(f))
127 rootCmd.AddCommand(containerRegistryCmd.NewCmd(f))
128 rootCmd.AddCommand(deployKeyCmd.NewCmdDeployKey(f))
129 rootCmd.AddCommand(deployTokenCmd.NewCmd(f))
130 rootCmd.AddCommand(dfCmd.NewCmd(f))
131 rootCmd.AddCommand(duoCmd.NewCmd(f))
132 rootCmd.AddCommand(governCmd.NewLegacyCmd(f))
133 rootCmd.AddCommand(gpgCmd.NewCmdGPGKey(f))
134 rootCmd.AddCommand(incidentCmd.NewCmdIncident(f))
135 rootCmd.AddCommand(issueCmd.NewCmdIssue(f))
136 rootCmd.AddCommand(iterationCmd.NewCmdIteration(f))
137 rootCmd.AddCommand(jobCmd.NewCmdJob(f))
138 rootCmd.AddCommand(labelCmd.NewCmdLabel(f))
139 rootCmd.AddCommand(milestoneCmd.NewCmdMilestone(f))
140 rootCmd.AddCommand(minderCmd.NewCmd(f))
141 rootCmd.AddCommand(mrCmd.NewCmdMR(f))
142 rootCmd.AddCommand(opentofuCmd.NewCmd(f))
143 rootCmd.AddCommand(orbitCmd.NewCmd(f))
144 rootCmd.AddCommand(packagesCmd.NewCmd(f))
145 rootCmd.AddCommand(attestationCmd.NewCmdAttestation(f))
146 rootCmd.AddCommand(pipelineCmd.NewCmdCI(f))
147 rootCmd.AddCommand(projectCmd.NewCmdRepo(f))
148 rootCmd.AddCommand(releaseCmd.NewCmdRelease(f))
149 rootCmd.AddCommand(runnerCmd.NewCmdRunner(f))
150 rootCmd.AddCommand(scheduleCmd.NewCmdSchedule(f))
151 rootCmd.AddCommand(searchCmd.NewCmd(f))
152 rootCmd.AddCommand(securefileCmd.NewCmdSecurefile(f))
153 rootCmd.AddCommand(securityCmd.NewCmd(f))
154 rootCmd.AddCommand(serviceAccountCmd.NewCmd(f))
155 rootCmd.AddCommand(snippetCmd.NewCmdSnippet(f))
156 rootCmd.AddCommand(sshCmd.NewCmdSSHKey(f))
157 rootCmd.AddCommand(stackCmd.NewCmdStack(f))
158 rootCmd.AddCommand(timelogCmd.NewCmd(f))
159 rootCmd.AddCommand(todoCmd.NewCmd(f))
160 rootCmd.AddCommand(tokenCmd.NewTokenCmd(f))
161 rootCmd.AddCommand(userCmd.NewCmdUser(f))
162 rootCmd.AddCommand(variableCmd.NewVariableCmd(f))
163 rootCmd.AddCommand(runnerControllerCmd.NewCmd(f))
164 rootCmd.AddCommand(skillsCmd.NewCmdSkills(f))
165 rootCmd.AddCommand(workitemsCmd.NewCmdWorkItems(f))
166 // TODO: This can probably be removed by GitLab 18.3
167 // See: https://gitlab.com/gitlab-org/cli/-/issues/7885
168 // Add global repo override flag but keep it hidden
169 cmdutils.AddGlobalRepoOverride(rootCmd, f)
171 rootCmd.Flags().BoolP("version", "v", false, "Show glab version information.")
172 return rootCmd
173}
Diagnostics6 git calls · 239 ms
CallStatusSizeTime0239 ms
discover200185 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=59849 git.response.cache=UPDATING git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:02001.8 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=232 git.response.bytes=1857 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1857 git.pkt.payload.max=1830 git.sideband.band1.bytes=1830 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1830 git.pack.trailer=fb03183b7909876778f740d196d7516811003517Open pack map
fetch2002.1 KiB232 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2160 git.response.cache=MISS git.response.duration_ms=232 git.fetch.wants=0c1a0fcf67ba99c246ca676c2e727bc1eb1d3a2f git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2160 git.pkt.payload.max=2133 git.sideband.band1.bytes=2133 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e2039aad4d70b8
- Request
- d0c042da…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format