GitLabgitlab-org
cli
main
1package cmdutils
3import (
4 "fmt"
5 "regexp"
6 "strconv"
7 "strings"
9 "github.com/MakeNowJust/heredoc/v2"
10 "github.com/spf13/cobra"
12 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
13)
15// PipelineInputsDescription documents the --input flag; commands append it to
16// their Long help text.
17var PipelineInputsDescription = heredoc.Docf(`
18 Specify one or more pipeline inputs using the %[1]s-i%[1]s or %[1]s--input%[1]s flag for each
19 input. Each input flag uses the format %[1]skey:value%[1]s.
21 The values are typed and will default to %[1]sstring%[1]s unless a type is explicitly
22 specified. To specify a type, use the %[1]stype(value)%[1]s syntax. For example,
23 %[1]skey:string(value)%[1]s will pass the string %[1]svalue%[1]s as the input.
25 Valid types are:
27 - %[1]sstring%[1]s: A string value. This type is the default. For example, %[1]skey:string(value)%[1]s.
28 - %[1]sint%[1]s: An integer value. For example, %[1]skey:int(42)%[1]s.
29 - %[1]sfloat%[1]s: A floating-point value. For example, %[1]skey:float(3.14)%[1]s.
30 - %[1]sbool%[1]s: A boolean value. For example, %[1]skey:bool(true)%[1]s.
31 - %[1]sarray%[1]s: An array of strings. For example, %[1]skey:array(foo,bar)%[1]s.
33 An array of strings can be specified with a trailing comma. For example,
34 %[1]skey:array(foo,bar,)%[1]s will pass the array %[1]s[foo, bar]%[1]s. %[1]sarray()%[1]s specifies an
35 empty array. To pass an array with the empty string, use %[1]sarray(,)%[1]s.
37 Value arguments containing parentheses should be escaped from the shell with
38 quotes. For example, %[1]s--input key:array(foo,bar)%[1]s should be written as
39 %[1]s--input 'key:array(foo,bar)'%[1]s.
40`, "`")
42// AddPipelineInputsFlag adds a flag to a cobra command for pipeline inputs.
43func AddPipelineInputsFlag(cmd *cobra.Command) {
44 cmd.Flags().StringArrayP("input", "i", nil, "Pass inputs to pipeline in format '<key>:<value>'. Cannot be used for merge request pipelines. See documentation for examples.")
45}
47// PipelineInputsFromFlags creates a gitlab.PipelineInputsOption from the "input" command line flag.
48//
49// Returns a nil map if the flag is not set.
50func PipelineInputsFromFlags(cmd *cobra.Command) (gitlab.PipelineInputsOption, error) {
51 flagVal, err := cmd.Flags().GetStringArray("input")
52 if err != nil {
53 return nil, err
54 }
56 if len(flagVal) == 0 {
57 return nil, nil
58 }
60 inputs := make(map[string]gitlab.PipelineInputValueInterface, len(flagVal))
62 for _, raw := range flagVal {
63 key, val, err := parsePipelineInput(raw)
64 if err != nil {
65 return nil, err
66 }
68 inputs[key] = val
69 }
71 return inputs, nil
72}
74var typedInputValueRE = regexp.MustCompile(`^(int|float|string|bool|array)\((.*)\)$`)
76func parsePipelineInput(s string) (string, gitlab.PipelineInputValueInterface, error) {
77 f := strings.SplitN(s, ":", 2)
78 if len(f) != 2 {
79 return "", nil, fmt.Errorf("invalid input %q: want \"key:value\"", s)
80 }
82 key, strValue := f[0], f[1]
83 if key == "" {
84 return "", nil, fmt.Errorf("key cannot be empty for input %q", s)
85 }
87 ms := typedInputValueRE.FindStringSubmatch(strValue)
88 switch {
89 case len(ms) < 3:
90 return key, gitlab.NewPipelineInputValue(strValue), nil
92 case ms[1] == "string":
93 return key, gitlab.NewPipelineInputValue(ms[2]), nil
95 case ms[1] == "array":
96 if ms[2] == "" {
97 return key, gitlab.NewPipelineInputValue([]string{}), nil
98 }
99 ms[2] = strings.TrimSuffix(ms[2], ",")
100 return key, gitlab.NewPipelineInputValue(strings.Split(ms[2], ",")), nil
102 case ms[1] == "bool":
103 v, err := strconv.ParseBool(ms[2])
104 if err != nil {
105 return "", nil, fmt.Errorf("strconv.ParseBool(%q): %w", ms[2], err)
106 }
108 return key, gitlab.NewPipelineInputValue(v), nil
110 case ms[1] == "int":
111 i, err := strconv.Atoi(ms[2])
112 if err != nil {
113 return "", nil, fmt.Errorf("strconv.Atoi(%q): %w", ms[2], err)
114 }
116 return key, gitlab.NewPipelineInputValue(i), nil
118 case ms[1] == "float":
119 f, err := strconv.ParseFloat(ms[2], 64)
120 if err != nil {
121 return "", nil, fmt.Errorf("strconv.ParseFloat(%q): %w", ms[2], err)
122 }
124 return key, gitlab.NewPipelineInputValue(f), nil
126 default:
127 // Unreachable
128 return "", nil, fmt.Errorf("unrecognized type %q in %q", ms[1], s)
129 }
130}
Diagnostics6 git calls · 267 ms
CallStatusSizeTime0267 ms
discover200185 B4 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 · hit3 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=HIT 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 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
fetchtree:02001.2 KiB · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=260 git.response.bytes=1238 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=c10f4b8b760c3fec7ed8ca85e428d5bc523f8e17 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=1238 git.pkt.payload.max=1211 git.sideband.band1.bytes=1211 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1211 git.pack.trailer=7373aa350f2a611db7d4116eb1450c92f18a27caOpen pack map
fetch2001.5 KiB260 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1575 git.response.cache=MISS git.response.duration_ms=260 git.fetch.wants=d5836c849027142a2e7be3d43bdb35c77f4ea2ae 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=1575 git.pkt.payload.max=1548 git.sideband.band1.bytes=1548 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
- a5e235c7a95fa594
- Request
- b36fd587…
- 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