Skip to content

Commit ea96815

Browse files
authored
fix: Implement repeated options (#138)
* implement repeated options update deps, upgrade to go 1.21
1 parent 7300430 commit ea96815

File tree

8 files changed

+182
-54
lines changed

8 files changed

+182
-54
lines changed

.milpa/docs/milpa/command/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ The environment available to a **script** is composed of four groups:
6666
2. `MILPA_OPT_*` variables hold values for every **option** defined, and
6767
3. [global environment variables](/.milpa/docs/milpa/environment.md) that affect `milpa`'s overall behavior.
6868

69+
> ℹ️ `variadic` arguments and `repeated` options are passed an array of values (i.e. read with `${MILPA_OPT_THING[@]}`)
70+
6971

7072
### Command metadata: `MILPA_COMMAND_*`
7173

.milpa/docs/milpa/command/spec.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ The `arguments` list describes the positional arguments that may be passed to a
8080
arguments:
8181
# available in to the command as the MILPA_ARG_INCREMENT environment variable
8282
- name: increment
83-
# this description shows up during auto-completion and in the command's help page
84-
descrption: the increment to apply to the last git version
83+
# this description shows up when rendering the command's help
84+
description: the increment to apply to the last git version
8585
# a default may be specified, it'll be passed to your command if none is provided
8686
default: patch
8787
# if marked as required, the command won't run unless this argument is provided
@@ -99,7 +99,7 @@ arguments:
9999
100100
## Options
101101
102-
The `options` map describes the named options that may be passed to a command. Options require a `name` and a `description`. The `name` of the option will become available to commands through the environment variable named `MILPA_OPT_$NAME` where `$NAME` means the uppercased value of key for an option. For example, an option at the key `scheme` will be available as your command's environment variable `MILPA_OPT_SCHEME`.
102+
The `options` map describes the named options that may be passed to a command (i.e. `--name value`). Options require a `name` and a `description`. The `name` of the option will become available to commands through the environment variable named `MILPA_OPT_$NAME` where `$NAME` means the uppercased value of key for an option. For example, an option at the key `scheme` will be available as your command's environment variable `MILPA_OPT_SCHEME`.
103103

104104
> ⚠️ Options are not available as positional arguments to your command. The same character restrictions as arguments apply to options.
105105

@@ -110,20 +110,22 @@ options:
110110
# it will be available to your script as the $MILPA_OPT_SCHEME environment variable
111111
# and may be specified on the command line as either `--scheme "semver"` or `--scheme=semver`.
112112
scheme:
113-
# options require a description, this will show during completions
114-
# and on the command's help page
113+
# options require a description, this will show when rendering the command's help
115114
description: Determines the format of the tags for this repo.
116115
# Sometimes, very commonly used flags might benefit from setting a short name
117116
# in this case, users would be able to use `-s calver`
118117
short-name: s
119118
# a default value may be passed to the command if none is provided by the user
120119
default: semver
121-
# the values provided at the command line
122120
# flags can be boolean. Since environment variables can only be strings,
123121
# false values (the default) will be passed as an empty string "", while
124122
# true values will be passed as the string "true"
125-
type: bool # or `string`
123+
type: string # or `bool`
124+
# string flags may be repeated multiple times
125+
# should an option be repeated, it's `default:` then must also be a list!
126+
repeated: false
126127
# the `values` property specifies how to provide completions and perform validation on
128+
# the values provided at the command line
127129
values: {}
128130
```
129131
---

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
golang 1.20.2
1+
golang 1.21.1

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
module github.com/unrob/milpa
22

3-
go 1.20
3+
go 1.21
44

55
require (
6-
git.rob.mx/nidito/chinampa v0.1.4
7-
github.com/alecthomas/chroma/v2 v2.12.0
6+
git.rob.mx/nidito/chinampa v0.2.1
7+
github.com/alecthomas/chroma/v2 v2.13.0
88
github.com/alessio/shellescape v1.4.2
99
github.com/bmatcuk/doublestar/v4 v4.6.1
1010
github.com/charmbracelet/glamour v0.7.0
1111
github.com/fatih/color v1.16.0
1212
github.com/sirupsen/logrus v1.9.3
1313
github.com/spf13/cobra v1.8.0
1414
github.com/spf13/pflag v1.0.5
15-
github.com/yuin/goldmark v1.7.0
15+
github.com/yuin/goldmark v1.7.1
1616
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
1717
gopkg.in/yaml.v3 v3.0.1
1818
)
1919

2020
require (
2121
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2222
github.com/aymerick/douceur v0.2.0 // indirect
23-
github.com/dlclark/regexp2 v1.10.0 // indirect
23+
github.com/dlclark/regexp2 v1.11.0 // indirect
2424
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
2525
github.com/go-playground/locales v0.14.1 // indirect
2626
github.com/go-playground/universal-translator v0.18.1 // indirect
27-
github.com/go-playground/validator/v10 v10.16.0 // indirect
27+
github.com/go-playground/validator/v10 v10.19.0 // indirect
2828
github.com/gorilla/css v1.0.1 // indirect
2929
github.com/inconshreveable/mousetrap v1.1.0 // indirect
30-
github.com/leodido/go-urn v1.2.4 // indirect
30+
github.com/leodido/go-urn v1.4.0 // indirect
3131
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3232
github.com/mattn/go-colorable v0.1.13 // indirect
3333
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -36,11 +36,11 @@ require (
3636
github.com/muesli/reflow v0.3.0 // indirect
3737
github.com/muesli/termenv v0.15.2 // indirect
3838
github.com/olekukonko/tablewriter v0.0.5 // indirect
39-
github.com/rivo/uniseg v0.4.4 // indirect
39+
github.com/rivo/uniseg v0.4.7 // indirect
4040
github.com/yuin/goldmark-emoji v1.0.2 // indirect
41-
golang.org/x/crypto v0.17.0 // indirect
42-
golang.org/x/net v0.18.0 // indirect
43-
golang.org/x/sys v0.15.0 // indirect
44-
golang.org/x/term v0.15.0 // indirect
41+
golang.org/x/crypto v0.22.0 // indirect
42+
golang.org/x/net v0.24.0 // indirect
43+
golang.org/x/sys v0.19.0 // indirect
44+
golang.org/x/term v0.19.0 // indirect
4545
golang.org/x/text v0.14.0 // indirect
4646
)

go.sum

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
git.rob.mx/nidito/chinampa v0.1.4 h1:rXmtuwYNtBmpLgWnNK7b5Z/styyuFfCP3RqL+qOzlok=
2-
git.rob.mx/nidito/chinampa v0.1.4/go.mod h1:isI138ZQ3GN/ZcuRrNPJ48fYnPC+U642gUe5bonhwUo=
3-
github.com/alecthomas/assert/v2 v2.2.1 h1:XivOgYcduV98QCahG8T5XTezV5bylXe+lBxLG2K2ink=
1+
git.rob.mx/nidito/chinampa v0.2.1 h1:DlXiu2j8aKNMb5Z2Vr291DwiCl19ikyGrVpJEQn5kIw=
2+
git.rob.mx/nidito/chinampa v0.2.1/go.mod h1:5X0gMayjUVs6biK6UoNZjEEc1wDEod+0PZg3ZrGgGUo=
3+
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
4+
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
45
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
5-
github.com/alecthomas/chroma/v2 v2.12.0 h1:Wh8qLEgMMsN7mgyG8/qIpegky2Hvzr4By6gEF7cmWgw=
6-
github.com/alecthomas/chroma/v2 v2.12.0/go.mod h1:4TQu7gdfuPjSh76j78ietmqh9LiurGF0EpseFXdKMBw=
6+
github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI=
7+
github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk=
78
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
8-
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
9+
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
10+
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
911
github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=
1012
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
1113
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
@@ -22,26 +24,28 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2224
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2325
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
2426
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
25-
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
26-
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
27+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
28+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
2729
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
2830
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
2931
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
3032
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
3133
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
34+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
3235
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
3336
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
3437
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
3538
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
36-
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
37-
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
39+
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
40+
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
3841
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
3942
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
4043
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
44+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
4145
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
4246
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
43-
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
44-
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
47+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
48+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
4549
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
4650
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
4751
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@@ -65,8 +69,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
6569
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6670
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6771
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
68-
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
69-
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
72+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
73+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
7074
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7175
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
7276
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
@@ -75,32 +79,28 @@ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyh
7579
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
7680
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
7781
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
78-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
79-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
8082
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
81-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
82-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
83-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
84-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
83+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
84+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
8585
github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
8686
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
87-
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
88-
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
87+
github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
88+
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
8989
github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s=
9090
github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY=
9191
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
9292
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
93-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
94-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
95-
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
96-
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
93+
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
94+
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
95+
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
96+
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
9797
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9898
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9999
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
100-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
101-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
102-
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
103-
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
100+
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
101+
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
102+
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
103+
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
104104
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
105105
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
106106
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

internal/command/environment.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ func envValue(opts command.Options, f *pflag.Flag) (*string, *string) {
6161
envName = fmt.Sprintf("%s%s", _c.OutputPrefixOpt, strings.ToUpper(strings.ReplaceAll(name, "-", "_")))
6262

6363
if opt := opts[name]; opt != nil {
64-
value = opt.ToString()
64+
if opt.Repeated {
65+
temp := []string{}
66+
for _, v := range opt.ToValue().([]string) {
67+
temp = append(temp, shellescape.Quote(v))
68+
}
69+
value = fmt.Sprintf("( %s )", strings.Join(temp, " "))
70+
} else {
71+
value = opt.ToString()
72+
}
6573
}
6674

6775
if value == "false" && f.Value.Type() == "bool" {
@@ -74,10 +82,14 @@ func envValue(opts command.Options, f *pflag.Flag) (*string, *string) {
7482

7583
// ToEnv writes shell variables to dst.
7684
func OptionsToEnv(cmd *command.Command, dst *[]string, prefix string) {
77-
cmd.Cobra.Flags().VisitAll(func(f *pflag.Flag) {
85+
cmd.FlagSet().VisitAll(func(f *pflag.Flag) {
7886
envName, value := envValue(cmd.Options, f)
7987
if envName != nil && value != nil {
80-
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, *envName, shellescape.Quote(*value)))
88+
if opt := cmd.Options[f.Name]; opt != nil && opt.Repeated {
89+
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, *envName, *value))
90+
} else {
91+
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, *envName, shellescape.Quote(*value)))
92+
}
8193
}
8294
})
8395
}

internal/command/environment_test.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,115 @@ func TestArgumentsToEnv(t *testing.T) {
183183
})
184184
}
185185
}
186+
187+
func TestOptionsToEnv(t *testing.T) {
188+
cases := []struct {
189+
Command *command.Command
190+
Args []string
191+
Expect []string
192+
Env []string
193+
}{
194+
{
195+
Args: []string{"test", "string", "--first", "something"},
196+
Expect: []string{"export MILPA_OPT_FIRST=something"},
197+
Command: &command.Command{
198+
Meta: Meta{
199+
Name: []string{"test", "string"},
200+
},
201+
Options: command.Options{
202+
"first": &command.Option{
203+
Type: command.ValueTypeString,
204+
},
205+
},
206+
},
207+
},
208+
{
209+
Args: []string{"test", "int", "--first", "1"},
210+
Expect: []string{"export MILPA_OPT_FIRST=1"},
211+
Command: &command.Command{
212+
Meta: Meta{
213+
Name: []string{"test", "int"},
214+
},
215+
Options: command.Options{
216+
"first": &command.Option{
217+
Type: command.ValueTypeInt,
218+
},
219+
},
220+
},
221+
},
222+
{
223+
Args: []string{"test", "bool", "--first"},
224+
Expect: []string{"export MILPA_OPT_FIRST=true"},
225+
Command: &command.Command{
226+
Meta: Meta{
227+
Name: []string{"test", "bool"},
228+
},
229+
Options: command.Options{
230+
"first": &command.Option{
231+
Type: command.ValueTypeBoolean,
232+
},
233+
},
234+
},
235+
},
236+
{
237+
Args: []string{"test", "bool-false", "--first", "false"},
238+
Expect: []string{"export MILPA_OPT_FIRST="},
239+
Command: &command.Command{
240+
Meta: Meta{
241+
Name: []string{"test", "bool-false"},
242+
},
243+
Options: command.Options{
244+
"first": &command.Option{
245+
Type: command.ValueTypeBoolean,
246+
},
247+
},
248+
},
249+
},
250+
{
251+
Args: []string{"test", "repeated", "--pato", "quem", "--pato", "quem quem"},
252+
Expect: []string{"export MILPA_OPT_PATO=( quem 'quem quem' )"},
253+
Command: &command.Command{
254+
Meta: Meta{
255+
Name: []string{"test", "repeated"},
256+
},
257+
Options: command.Options{
258+
"pato": &command.Option{
259+
Type: command.ValueTypeString,
260+
Repeated: true,
261+
},
262+
},
263+
},
264+
},
265+
}
266+
267+
for _, c := range cases {
268+
t.Run(c.Command.FullName(), func(t *testing.T) {
269+
dst := []string{}
270+
c.Command.SetBindings()
271+
err := c.Command.FlagSet().Parse(c.Args)
272+
if err != nil {
273+
t.Fatalf("Could not parse test arguments (%+v): %s", c.Args, err)
274+
}
275+
c.Command.Options.Parse(c.Command.FlagSet())
276+
OptionsToEnv(c.Command, &dst, "export ")
277+
278+
if err := c.Command.Options.AreValid(); err != nil {
279+
t.Fatalf("Unexpected failure validating: %s", err)
280+
}
281+
282+
for _, expected := range c.Expect {
283+
found := false
284+
for _, actual := range dst {
285+
if strings.HasPrefix(actual, expected) {
286+
found = true
287+
break
288+
}
289+
}
290+
291+
if !found {
292+
t.Fatalf("Expected line %v not found in %v", expected, dst)
293+
}
294+
}
295+
})
296+
}
297+
}

repos/internal/commands/dev/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [[ "$MILPA_OPT_COVERAGE" ]]; then
99
milpa dev test unit --coverage
1010
milpa dev test integration --coverage
1111
mkdir -p "$MILPA_ROOT/test/coverage/doctor"
12-
GOCOVERDIR="$MILPA_ROOT/test/coverage/doctor" milpa itself doctor
12+
MILPA_PATH="$(pwd)/.milpa" MILPA_PATH_PARSED=true GOCOVERDIR="$MILPA_ROOT/test/coverage/doctor" milpa itself doctor
1313
milpa dev test coverage-report
1414
milpa dev build
1515
else

0 commit comments

Comments
 (0)