Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## [Unreleased]

### Changed
- **シェル補完(bash・zsh)が、`--context NAME` を受け付けるすべてのサブコマンドで `--context` を出すようにしました(#435)。**
これまでは `open` と `project post-start` だけでした。`up`・`down`・`ps`・`login`・`scale`・`build`・`rebuild`、
`project` / `container` の配下(`logs`・`profile up|down|list` を含む)、`env exec`・`env token` で、`-` を打って補完すると
`--context` が候補に出ます(`devbase up web -<TAB>` のようにプロジェクト名の後でも出ます)。値(docker context の名前)は補完しません。
`-` で始まらない語の候補は変わりません。

### Fixed
- **プロジェクトの `env` に `DEV_SERVICE_NAME=` と空で書いたとき、開発サービス名を `dev` として扱うようにしました(#425)。**
これまで `devbase build` は `dev` を建てる一方、`up`・`login`・`open`・`post-start`・`scale`・`--expires` の判定・
Expand Down
8 changes: 5 additions & 3 deletions docs/specifications/cli-argument-resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ graph TD
| --- | --- |
| `bin/devbase` の `_PROJECT_NAME_SUBCOMMANDS` | `project` の直下で `[name]` を取る parser の名前の集合に等しい |
| `bin/devbase` の `_NAME_RESOLVABLE_SHORTCUTS` | `cli.SHORTCUTS` のキーと `build` の和に等しい。あわせて、トップレベルで `[name]` を取る parser がすべて `cli.SHORTCUTS` にあること |
| `etc/devbase-completion.bash` | 一時ディレクトリの `projects/` を `DEVBASE_ROOT` にして補完を実行し、`[name]` の集合から補完の例外を引いたすべての道の名前の位置でプロジェクト名が候補に出る。`project` / `container` の直下で `[name]` か `--context` を取るサブコマンド(入れ子は親の `profile` として数える)が、そのグループのサブコマンドの候補に含まれる |
| `etc/_devbase` | zsh を起動せず内容を読む。`case "$words[2]"` から字下げの深さで道の分岐(`up\|down)` のような `\|` 区切りの見出し)を辿り、その本体に `_devbase_project_names` がある。`project_subcommands` / `container_subcommands` の一覧に bash と同じサブコマンドが含まれる |
| `etc/devbase-completion.bash` | 一時ディレクトリの `projects/` を `DEVBASE_ROOT` にして補完を実行し、`[name]` の集合から補完の例外を引いたすべての道の名前の位置でプロジェクト名が候補に出る。`--context` の集合のすべての道(`container` の道は `ct` で始めても)で `devbase <道> -` の候補に `--context` が出る。`[name]` の集合から補完の例外を引いた道では、`devbase <道> web -` の候補にも `--context` が出る。`project` / `container` の直下で `[name]` か `--context` を取るサブコマンド(入れ子は親の `profile` として数える)が、そのグループのサブコマンドの候補に含まれる |
| `etc/_devbase` | zsh を起動せず内容を読む。`case "$words[2]"` から字下げの深さで道の分岐(`up\|down)` のような `\|` 区切りの見出し)を辿り、`[name]` の集合から補完の例外を引いた道の本体に `_devbase_project_names` がある。`--context` の集合のすべての道の本体に、値の補完を持たない `'--context[...]:context:'`(`:context:` の後ろに補完の関数を置かない形)がある。`project_subcommands` / `container_subcommands` の一覧に bash と同じサブコマンドが含まれる |
| この節の 2 つの表 | 見出し `` #### `[name]` を受け付けるサブコマンド `` と `` #### `--context` を受け付けるサブコマンド `` の直後の表を読む。1 列目は `devbase <グループ...> <sub>` の形で、間の語が道の頭になる。2 列目にバッククォートで並べた語を `<sub>` に入れる。表は `[name]` の集合・`--context` の集合にそれぞれ等しい |

補完の例外は `project profile up` / `down` / `list` の 3 つで、理由は「1 つ目の位置引数は、値が 1 個なら
プロファイル名、2 個ならプロジェクト名になり、補完の時点ではどちらか決まらない」。一致テストは例外を
理由つきの一覧として持ち、例外の道が `[name]` の集合に実在すること・理由が空でないことも確かめる。
補完が `--context` の値を補完するかどうか(今は `open` と `post-start` だけ)は比べない。
補完は `--context` の値(docker context の名前)を bash でも zsh でも補完しない。zsh は一致テストが上の
`--context` の指定の形で確かめ、bash は `tests/cli/test_completion.py` が `--context` の直後の候補が
0 件であることを代表の道で確かめる。

### 名前の形

Expand Down
98 changes: 78 additions & 20 deletions etc/_devbase
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,35 @@ _devbase() {
'rotate:Rotate old snapshots'
)

# --context NAME を取るサブコマンドは、どれも値を補完しない --context を出す (#435)。
case "$words[2]" in
login)
_values 'index' 1 2
_arguments \
'--context[Docker context]:context:' \
'1:index:(1 2)'
;;
build)
_arguments \
'--context[Docker context]:context:' \
'1:image:'
;;
# トップレベルシノニム: up/down/ps/scale/rebuild は [name] を取るためプロジェクト名を補完。
up|down|rebuild)
_devbase_project_names
_arguments \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
ps)
if [[ "$words[3]" == -* || -n "$words[3]" ]]; then
_arguments '--all[Show all containers]' '-a[Show all containers]'
else
_devbase_project_names
fi
_arguments \
'--all[Show all containers]' \
'-a[Show all containers]' \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
scale)
_devbase_project_names
_arguments \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
open)
_arguments \
Expand All @@ -180,13 +192,19 @@ _devbase() {
project)
case "$words[3]" in
up|down|rebuild)
_devbase_project_names
_arguments \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
login)
_values 'index' 1 2
_arguments \
'--context[Docker context]:context:' \
'1:index:(1 2)'
;;
scale)
_devbase_project_names
_arguments \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
ps)
# name (positional) と -a フラグを _arguments に統合。
Expand All @@ -195,17 +213,21 @@ _devbase() {
_arguments \
'--all[Show all containers]' \
'-a[Show all containers]' \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
logs)
_arguments \
'--follow[Follow log output]' \
'-f[Follow log output]' \
'--tail[Number of lines]:lines:' \
'--context[Docker context]:context:' \
'1:name:_devbase_project_names'
;;
build)
_arguments '1:image:'
_arguments \
'--context[Docker context]:context:' \
'1:image:'
;;
list)
_arguments \
Expand All @@ -216,7 +238,16 @@ _devbase() {
'-i[(compat) interactive selection, default]'
;;
profile)
_values 'operation' up down list
case "$words[4]" in
up|down|list)
_arguments \
'--context[Docker context]:context:' \
'*:profile:'
;;
*)
_values 'operation' up down list
;;
esac
;;
open)
_arguments \
Expand All @@ -236,26 +267,48 @@ _devbase() {
;;
container|ct)
case "$words[3]" in
up|down|rebuild)
_arguments '--context[Docker context]:context:'
;;
login)
_values 'index' 1 2
_arguments \
'--context[Docker context]:context:' \
'1:index:(1 2)'
;;
scale)
_values 'new_scale' 1 2 3 4 5
_arguments \
'--context[Docker context]:context:' \
'1:new_scale:(1 2 3 4 5)'
;;
ps)
_arguments '--all[Show all containers]' '-a[Show all containers]'
_arguments \
'--all[Show all containers]' \
'-a[Show all containers]' \
'--context[Docker context]:context:'
;;
logs)
_arguments \
'--follow[Follow log output]' \
'-f[Follow log output]' \
'--tail[Number of lines]:lines:'
'--tail[Number of lines]:lines:' \
'--context[Docker context]:context:'
;;
build)
_arguments '1:image:'
_arguments \
'--context[Docker context]:context:' \
'1:image:'
;;
profile)
_values 'operation' up down list
case "$words[4]" in
up|down|list)
_arguments \
'--context[Docker context]:context:' \
'*:profile:'
;;
*)
_values 'operation' up down list
;;
esac
;;
open)
_arguments \
Expand Down Expand Up @@ -328,7 +381,12 @@ _devbase() {
'--keep-last[Keep only the last N backup directories]:n:'
;;
exec)
_arguments '*:command:_command_names -e'
_arguments \
'--context[Docker context]:context:' \
'*:command:_command_names -e'
;;
token)
_arguments '--context[Docker context]:context:'
;;
encrypt|decrypt)
_arguments \
Expand Down
Loading
Loading