GitLabgitlab-org
cli
main
1package config
3import (
4 "fmt"
5 "slices"
6 "strings"
7)
9// EnvVarGroup splits the reference into sections, since a single table of
10// every variable is hard to scan.
11type EnvVarGroup string
13const (
14 GroupAccess EnvVarGroup = "GitLab access variables"
15 GroupBehaviour EnvVarGroup = "`glab` configuration variables"
16 GroupOther EnvVarGroup = "Other variables"
17)
19var EnvVarGroupOrder = []EnvVarGroup{GroupAccess, GroupBehaviour, GroupOther}
21// EnvVarDoc is one entry of the environment variable reference. Description
22// follows the same convention as KeyDef.Description: plain prose with
23// 'single-quoted' literals, left for the renderer to mark up.
24type EnvVarDoc struct {
25 Name string
26 ConfigKey string
27 Default string
28 Description string
29 Group EnvVarGroup
30}
32// nonSchemaEnvVars are read directly with os.Getenv rather than resolved
33// through KeySchema, so they have to be listed by hand.
34var nonSchemaEnvVars = []EnvVarDoc{
35 {Name: "FORCE_HYPERLINKS", ConfigKey: "display_hyperlinks", Description: "Set to 1 to force terminal hyperlinks when not writing to a TTY. A falsy value falls through to 'display_hyperlinks'.", Group: GroupBehaviour},
36 {Name: "GITLAB_GROUP", Description: "Default group for commands that list merge requests, issues, and variables. Used only when '--group' is not given.", Group: GroupAccess},
37 {Name: "GITLAB_HEAD_REPO", Description: "Source repository for 'glab mr create'. Used only when '--head' is not given.", Group: GroupAccess},
38 {Name: "GITLAB_RELEASE_ASSETS_USE_PACKAGE_REGISTRY", Description: "Set to true or 1 to upload release assets to the generic package registry of the project. The '--use-package-registry' flag takes precedence.", Group: GroupBehaviour},
39 {Name: "GITLAB_REPO", Description: "Default repository for commands that accept '--repo'. Used only when '--repo' is not given.", Group: GroupAccess},
40 {Name: "GLAB_CONFIG_DIR", Default: "~/.config/glab-cli", Description: "Directory holding the global configuration file. Takes priority over the XDG locations.", Group: GroupBehaviour},
41 {Name: "GLAB_DEBUG_HTTP", Default: "false", Description: "Set to true to output HTTP transport information (request and response).", Group: GroupBehaviour},
42 {Name: "GLAB_ENABLE_CI_AUTOLOGIN", Default: "false", Description: "Set to true to enable auto-login in GitLab CI. Together with 'GITLAB_CI=true', glab signs in using predefined CI/CD variables such as 'CI_SERVER_FQDN' and 'CI_JOB_TOKEN', and ignores host variables such as 'GITLAB_HOST'.", Group: GroupAccess},
43 {Name: "GLAB_FORCE_HYPERLINKS", ConfigKey: "display_hyperlinks", Description: "Set to true to force terminal hyperlinks when not writing to a TTY.", Group: GroupBehaviour},
44 {Name: "NO_COLOR", Description: "Set to any value to avoid printing ANSI escape sequences for color output.", Group: GroupBehaviour},
45}
47// groupFor splits per-host keys, which describe reaching an instance, from
48// global keys, which describe how glab behaves. The exceptions are listed.
49func groupFor(kd KeyDef) EnvVarGroup {
50 switch kd.Name {
51 case "host":
52 return GroupAccess
53 case "remote_alias":
54 return GroupOther
55 }
56 if kd.Scope == ScopePerHost {
57 return GroupAccess
58 }
59 return GroupBehaviour
60}
62// undocumentedEnvVarKeys resolve from the environment like any other key, but
63// listing them would advertise a way to set them that nobody can act on: a job
64// token only works inside CI, where it arrives as CI_JOB_TOKEN via auto-login.
65var undocumentedEnvVarKeys = map[string]struct{}{
66 "job_token": {},
67}
69// EnvVarsForKey returns the environment variables that set kd, most preferred
70// first. TypeList keys are read straight out of the YAML rather than through
71// Config.Get, so no environment variable reaches them.
72func EnvVarsForKey(kd KeyDef) []string {
73 if kd.Type == TypeList {
74 return nil
75 }
76 if _, ok := undocumentedEnvVarKeys[kd.Name]; ok {
77 return nil
78 }
79 return schemaEnvVars(kd.Name)
80}
82// EnvVars returns every environment variable glab reads, one entry per name so
83// that a reader searching for the name they already have set finds it. Entries
84// sort by the preferred name for the key, keeping alternatives directly beneath
85// the entry that carries the real description.
86func EnvVars() []EnvVarDoc {
87 type ordered struct {
88 doc EnvVarDoc
89 primary string
90 rank int
91 }
93 var rows []ordered
94 for _, ev := range nonSchemaEnvVars {
95 rows = append(rows, ordered{doc: ev, primary: ev.Name})
96 }
97 for _, kd := range KeySchema {
98 if !kd.UserSettable || kd.HelpHidden {
99 continue
100 }
101 envVars := EnvVarsForKey(kd)
102 for i, name := range envVars {
103 desc := kd.Description
104 if i > 0 {
105 desc = fmt.Sprintf("Alternative name for '%s', checked after it.", envVars[0])
106 }
107 rows = append(rows, ordered{
108 doc: EnvVarDoc{
109 Name: name,
110 ConfigKey: kd.Name,
111 Default: kd.Default,
112 Description: desc,
113 Group: groupFor(kd),
114 },
115 primary: envVars[0],
116 rank: i,
117 })
118 }
119 }
121 slices.SortFunc(rows, func(a, b ordered) int {
122 if c := strings.Compare(a.primary, b.primary); c != 0 {
123 return c
124 }
125 return a.rank - b.rank
126 })
128 out := make([]EnvVarDoc, 0, len(rows))
129 for _, r := range rows {
130 out = append(out, r.doc)
131 }
132 return out
133}
135// EnvVarSection is one rendered group of the reference.
136type EnvVarSection struct {
137 Group EnvVarGroup
138 Vars []EnvVarDoc
139}
141// EnvVarsByGroup returns EnvVars split into EnvVarGroupOrder, skipping any
142// group that ends up empty.
143func EnvVarsByGroup() []EnvVarSection {
144 var out []EnvVarSection
145 all := EnvVars()
146 for _, group := range EnvVarGroupOrder {
147 var vars []EnvVarDoc
148 for _, ev := range all {
149 if ev.Group == group {
150 vars = append(vars, ev)
151 }
152 }
153 if len(vars) > 0 {
154 out = append(out, EnvVarSection{Group: group, Vars: vars})
155 }
156 }
157 return out
158}
Diagnostics6 git calls · 30 ms
CallStatusSizeTime030 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=2 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 KiB · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=2 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
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=2 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
fetchcombine:blob:none+tree:2 · deepen 12004.2 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=4273 git.response.cache=HIT git.response.duration_ms=3 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:02001.4 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=22 git.response.bytes=1391 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=e9da9edfdcf44933ee5fa121d411de326220161c 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=1391 git.pkt.payload.max=1364 git.sideband.band1.bytes=1364 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1364 git.pack.trailer=bf750bd385ed98d15e1fea1289d3b00caa61d64cOpen pack map
fetch2002.3 KiB · hit22 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2391 git.response.cache=HIT git.response.duration_ms=22 git.fetch.wants=01b176cdae9013961893c79a5df567cd5eb8733a 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=2391 git.pkt.payload.max=2364 git.sideband.band1.bytes=2364 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
- a5e263a959fe224d
- Request
- 2a5f6222…
- 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