Skip to content

Commit 5daa46e

Browse files
committed
Support multiple args for doco tag command
1 parent 59fb7dd commit 5daa46e

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

CLI.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* [`jq`](#jq)
2424
* [`jqc`](#jqc)
2525
* [`sh`](#sh)
26-
* [`tag` *[tag]*](#tag-tag)
26+
* [`tag` *[tags...]*](#tag-tags)
2727

2828
<!-- tocstop -->
2929

@@ -302,11 +302,11 @@ doco.jqc() { compose-config; local JQ_CMD=(jq-tty); RUN_JQ "$@" <<<"$COMPOSED_JS
302302
doco.sh() { doco exec bash "$@"; }
303303
```
304304

305-
#### `tag` *[tag]*
305+
#### `tag` *[tags...]*
306306

307-
Tag the current service's `image` with *tag*. If no *tag* is given, outputs the service's `image`.
307+
Tag the current service's `image` with *tags*. If no *tags* are given, outputs the service's `image`.
308308

309-
If *tag* contains a `:`, it is passed to the `docker tag` command as-is. Otherwise, if it contains a `/`, `:latest` will be added to the end of it. If it contains neither a `:` nor a `/`, it is appended to the base image with a `:`.
309+
If a *tag* contains a `:`, it is passed to the `docker tag` command as-is. Otherwise, if it contains a `/`, `:latest` will be added to the end of it. If it contains neither a `:` nor a `/`, it is appended to the base image with a `:`.
310310

311311
That is, if a service `foo` has an `image` of `foo/bar:1.2` then:
312312

@@ -317,16 +317,20 @@ That is, if a service `foo` has an `image` of `foo/bar:1.2` then:
317317

318318
Exactly one service must be selected, either explicitly or via the `--tag-default` or`--default` targets. The service must have an `image` key, or the command will fail.
319319

320+
(Note: this command tags the image specified by the service's `image` setting, *not* the image currently in use by the service. If the `image` changed (or there's a newer image with that tag) since the last service `up`, you may be tagging the wrong image.)
321+
320322
```shell
321323
doco.tag() {
322324
require-services 1 tag || return
323-
REPLY="$(CLEAR_FILTERS; FILTER 'services[%s].image' "$REPLY"; RUN_JQ -r <"$DOCO_CONFIG")"
324-
case ${1-} in
325-
?*:*) docker tag "$REPLY" "$1" ;;
326-
*/*) docker tag "$REPLY" "$1:latest" ;;
327-
'') echo "$REPLY" ;;
328-
*) docker tag "$REPLY" "${REPLY%:*}:$1";;
329-
esac
325+
set -- "$(CLEAR_FILTERS; FILTER 'services[%s].image' "$REPLY"; RUN_JQ -r <"$DOCO_CONFIG")" "$@"
326+
(($#>1))||{ echo "$1"; return; }
327+
for REPLY in "${@:2}"; do
328+
case $REPLY in
329+
?*:*) docker tag "$1" "$REPLY" ;;
330+
*/*) docker tag "$1" "$REPLY:latest" ;;
331+
*) docker tag "$1" "${1%:*}:$REPLY";;
332+
esac
333+
done
330334
}
331335
```
332336

bin/doco

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,15 @@ doco.jqc() { compose-config; local JQ_CMD=(jq-tty); RUN_JQ "$@" <<<"$COMPOSED_JS
10351035
doco.sh() { doco exec bash "$@"; }
10361036
doco.tag() {
10371037
require-services 1 tag || return
1038-
REPLY="$(CLEAR_FILTERS; FILTER 'services[%s].image' "$REPLY"; RUN_JQ -r <"$DOCO_CONFIG")"
1039-
case ${1-} in
1040-
?*:*) docker tag "$REPLY" "$1" ;;
1041-
*/*) docker tag "$REPLY" "$1:latest" ;;
1042-
'') echo "$REPLY" ;;
1043-
*) docker tag "$REPLY" "${REPLY%:*}:$1";;
1044-
esac
1038+
set -- "$(CLEAR_FILTERS; FILTER 'services[%s].image' "$REPLY"; RUN_JQ -r <"$DOCO_CONFIG")" "$@"
1039+
(($#>1))||{ echo "$1"; return; }
1040+
for REPLY in "${@:2}"; do
1041+
case $REPLY in
1042+
?*:*) docker tag "$1" "$REPLY" ;;
1043+
*/*) docker tag "$1" "$REPLY:latest" ;;
1044+
*) docker tag "$1" "${1%:*}:$REPLY";;
1045+
esac
1046+
done
10451047
}
10461048
#!/usr/bin/env bash
10471049

specs/CLI-Commands.cram.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ If stdout is a TTY, the output is paged (using `$DOCO_PAGER` or `less -FRX`) and
238238
[64]
239239
~~~
240240

241-
#### `tag` *[tag]*
241+
#### `tag` *[tags...]*
242242

243-
Tag the current service's `image` with *tag*. If no *tag* is given, outputs the service's `image`.
243+
Tag the current service's `image` with *tags*. If no *tags* are given, outputs the service's `image`.
244244

245-
If *tag* contains a `:`, it is passed to the `docker tag` command as-is. Otherwise, if it contains a `/`, `:latest` will be added to the end of it. If it contains neither a `:` nor a `/`, it is appended to the base image with a `:`.
245+
If a *tag* contains a `:`, it is passed to the `docker tag` command as-is. Otherwise, if it contains a `/`, `:latest` will be added to the end of it. If it contains neither a `:` nor a `/`, it is appended to the base image with a `:`.
246246

247247
That is, if a service `foo` has an `image` of `foo/bar:1.2` then:
248248

@@ -253,16 +253,17 @@ That is, if a service `foo` has an `image` of `foo/bar:1.2` then:
253253

254254
Exactly one service must be selected, either explicitly or via the `--tag-default` or `--default` targets. The service must have an `image` key, or the command will fail.
255255

256+
(Note: this command tags the image specified by the service's `image` setting, *not* the image currently in use by the service. If the `image` changed (or there's a newer image with that tag) since the last service `up`, you may be tagging the wrong image.)
257+
256258
~~~sh
257259
$ doco example1 tag
258260
bash
259261

260-
$ doco example1 tag bing/bang:boom
262+
$ doco example1 tag zing bing/bang:boom
263+
docker tag bash bash:zing
261264
docker tag bash bing/bang:boom
262265

263-
$ doco example1 tag bing/bang
266+
$ doco example1 tag bing/bang boom
264267
docker tag bash bing/bang:latest
265-
266-
$ doco example1 tag boom
267268
docker tag bash bash:boom
268269
~~~

0 commit comments

Comments
 (0)