Skip to content

Commit 52c80bc

Browse files
committed
Move commandline interface to typer
This commit moves the kiwi commandline and plugin interface to typer and drops the use of docopt. Typer is based on python type hints and allows for a more modern way to define Cli interfaces and auto completion, even for plugins. Also docopt is split into an old and a next generation variant and allows us to get rid of spec file hacks as well as documentation rendering hacks.
1 parent 01a0573 commit 52c80bc

33 files changed

+1458
-1214
lines changed

Makefile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ install:
3535
done
3636
# completion
3737
install -d -m 755 ${buildroot}usr/share/bash-completion/completions
38-
$(python) helper/completion_generator.py \
39-
> ${buildroot}usr/share/bash-completion/completions/kiwi-ng
38+
install -m 644 completions/bash-completion \
39+
${buildroot}usr/share/bash-completion/completions/kiwi-ng
4040
# kiwi default configuration
4141
install -d -m 755 ${buildroot}etc
4242
install -m 644 kiwi.yml ${buildroot}etc/kiwi.yml
@@ -80,16 +80,6 @@ valid:
8080
fi \
8181
done
8282

83-
git_attributes:
84-
# the following is required to update the $Format:%H$ git attribute
85-
# for details on when this target is called see setup.py
86-
git archive HEAD kiwi/version.py | tar -x
87-
88-
clean_git_attributes:
89-
# cleanup version.py to origin state
90-
# for details on when this target is called see setup.py
91-
git checkout kiwi/version.py
92-
9383
setup:
9484
poetry install --all-extras
9585

@@ -162,7 +152,7 @@ prepare_for_pypi: clean setup
162152
# ci-publish-to-pypi.yml github action
163153
poetry build --format=sdist
164154

165-
clean: clean_git_attributes
155+
clean:
166156
rm -rf dist
167157
rm -rf doc/build
168158
rm -rf doc/dist

completions/bash-completion

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#========================================
2+
# _kiwi
3+
#----------------------------------------
4+
function setupCompletionLine {
5+
local comp_line=$(echo $COMP_LINE | sed -e 's@kiwi-ng@kiwi@')
6+
local result_comp_line
7+
local prev_was_option=0
8+
for item in $comp_line; do
9+
if [ $prev_was_option = 1 ];then
10+
prev_was_option=0
11+
continue
12+
fi
13+
if [[ $item =~ -.* ]];then
14+
prev_was_option=1
15+
continue
16+
fi
17+
result_comp_line="$result_comp_line $item"
18+
done
19+
echo $result_comp_line
20+
}
21+
22+
function _kiwi {
23+
local cur prev opts
24+
_get_comp_words_by_ref cur prev
25+
local cmd=$(setupCompletionLine | awk -F ' ' '{ print $NF }')
26+
for comp in $prev $cmd;do
27+
case "$comp" in
28+
"image")
29+
__comp_reply "info resize"
30+
return 0
31+
;;
32+
"result")
33+
__comp_reply "bundle list"
34+
return 0
35+
;;
36+
"system")
37+
__comp_reply "build create prepare update"
38+
return 0
39+
;;
40+
"build")
41+
__comp_reply "--add-bootstrap-package --add-container-label --add-package --add-repo --add-repo-credentials --allow-existing-root --clear-cache --delete-package --description --help --ignore-repos --ignore-repos-used-for-build --set-container-derived-from --set-container-tag --set-release-version --set-repo --set-repo-credentials --set-type-attr=<attribute --signing-key --target-dir help"
42+
return 0
43+
;;
44+
"bundle")
45+
__comp_reply "--bundle-dir --bundle-format --help --id --package-as-rpm --target-dir --zsync-source help"
46+
return 0
47+
;;
48+
"create")
49+
__comp_reply "--help --root --signing-key --target-dir help"
50+
return 0
51+
;;
52+
"info")
53+
__comp_reply "--description --help --list-profiles --resolve-package-list help"
54+
return 0
55+
;;
56+
"list")
57+
__comp_reply "--help --target-dir help"
58+
return 0
59+
;;
60+
"prepare")
61+
__comp_reply "--add-bootstrap-package --add-container-label --add-package --add-repo --add-repo-credentials --allow-existing-root --clear-cache --delete-package --description --help --ignore-repos --ignore-repos-used-for-build --root --set-container-derived-from --set-container-tag --set-release-version --set-repo --set-repo-credentials --set-type-attr=<attribute --signing-key help"
62+
return 0
63+
;;
64+
"resize")
65+
__comp_reply "--help --root --size --target-dir help"
66+
return 0
67+
;;
68+
"update")
69+
__comp_reply "--add-package --delete-package --help --root help"
70+
return 0
71+
;;
72+
esac
73+
done
74+
__comp_reply "--help --logfile --profile --version help image result system"
75+
return 0
76+
}
77+
#========================================
78+
# comp_reply
79+
#----------------------------------------
80+
function __comp_reply {
81+
word_list=$@
82+
COMPREPLY=($(compgen -W "$word_list" -- ${cur}))
83+
}
84+
85+
complete -F _kiwi -o default kiwi
86+
complete -F _kiwi -o default kiwi-ng

doc/source/commands/image_info.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ SYNOPSIS
1010
1111
kiwi-ng [global options] service <command> [<args>]
1212
13-
kiwi-ng image info -h | --help
13+
kiwi-ng image info --help
1414
kiwi-ng image info --description=<directory>
1515
[--resolve-package-list]
1616
[--list-profiles]
1717
[--print-kiwi-env]
1818
[--ignore-repos]
1919
[--add-repo=<source,type,alias,priority>...]
2020
[--print-xml|--print-yaml]
21-
kiwi-ng image info help
2221
2322
.. _db_image_info_desc:
2423

doc/source/commands/image_resize.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ SYNOPSIS
1212
1313
kiwi-ng [global options] service <command> [<args>]
1414
15-
kiwi-ng image resize -h | --help
15+
kiwi-ng image resize --help
1616
kiwi-ng image resize --target-dir=<directory> --size=<size>
1717
[--root=<directory>]
18-
kiwi-ng image resize help
1918
2019
.. _db_kiwi_image_resize_desc:
2120

doc/source/commands/kiwi.rst

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,13 @@ SYNOPSIS
88

99
.. code:: bash
1010
11-
kiwi-ng [global options] service <command> [<args>]
12-
13-
kiwi-ng -h | --help
14-
kiwi-ng [--profile=<name>...]
15-
[--temp-dir=<directory>]
16-
[--type=<build_type>]
17-
[--logfile=<filename>]
18-
[--logsocket=<socketfile>]
19-
[--loglevel=<number>]
20-
[--debug]
21-
[--debug-run-scripts-in-screen]
22-
[--color-output]
23-
[--config=<configfile>]
24-
[--kiwi-file=<kiwifile>]
25-
image <command> [<args>...]
26-
kiwi-ng [--logfile=<filename>]
27-
[--logsocket=<socketfile>]
28-
[--loglevel=<number>]
29-
[--debug]
30-
[--debug-run-scripts-in-screen]
31-
[--color-output]
32-
[--config=<configfile>]
33-
result <command> [<args>...]
34-
kiwi-ng [--profile=<name>...]
35-
[--shared-cache-dir=<directory>]
36-
[--temp-dir=<directory>]
37-
[--target-arch=<name>]
38-
[--type=<build_type>]
39-
[--logfile=<filename>]
40-
[--logsocket=<socketfile>]
41-
[--loglevel=<number>]
42-
[--debug]
43-
[--debug-run-scripts-in-screen]
44-
[--color-output]
45-
[--config=<configfile>]
46-
[--kiwi-file=<kiwifile>]
47-
system <command> [<args>...]
48-
kiwi-ng -v | --version
49-
kiwi-ng help
11+
kiwi-ng --help | --version
12+
13+
kiwi-ng [global options] image <command> [<args>...]
14+
kiwi-ng [global options] result <command> [<args>...]
15+
kiwi-ng [global options] system <command> [<args>...]
16+
17+
kiwi-ng help [kiwi::COMMAND::SUBCOMMAND]
5018
5119
.. _db_commands_kiwi_desc:
5220

@@ -95,8 +63,8 @@ GLOBAL OPTIONS
9563
--config=<configfile>
9664

9765
Use specified runtime configuration file. If not specified, the
98-
runtime configuration is expected to be in the :file:`~/.config/kiwi/config.yml`
99-
or :file:`/etc/kiwi.yml` files.
66+
runtime configuration is expected to be in the
67+
:file:`~/.config/kiwi/config.yml` or :file:`/etc/kiwi.yml` files.
10068

10169
--debug
10270

doc/source/commands/result_bundle.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ SYNOPSIS
1010
1111
kiwi-ng [global options] service <command> [<args>]
1212
13-
kiwi-ng result bundle -h | --help
13+
kiwi-ng result bundle --help
1414
kiwi-ng result bundle --target-dir=<directory> --id=<bundle_id> --bundle-dir=<directory>
1515
[--bundle-format=<format>]
1616
[--zsync_source=<download_location>]
1717
[--package-as-rpm]
18-
kiwi-ng result bundle help
1918
2019
.. _db_kiwi_result_bundle_desc:
2120

doc/source/commands/result_list.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ SYNOPSIS
1010
1111
kiwi-ng [global options] service <command> [<args>]
1212
13-
kiwi-ng result list -h | --help
13+
kiwi-ng result list --help
1414
kiwi-ng result list --target-dir=<directory>
15-
kiwi-ng result list help
1615
1716
.. _db_kiwi_result_list_desc:
1817

doc/source/commands/system_build.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
1313
kiwi-ng [global options] service <command> [<args>]
1414
15-
kiwi-ng system build -h | --help
15+
kiwi-ng system build --help
1616
kiwi-ng system build --description=<directory> --target-dir=<directory>
1717
[--allow-existing-root]
1818
[--clear-cache]
@@ -31,7 +31,6 @@ SYNOPSIS
3131
[--set-type-attr=<attribute=value>...]
3232
[--set-release-version=<version>]
3333
[--signing-key=<key-file>...]
34-
kiwi-ng system build help
3534
3635
.. _db_kiwi_system_build_desc:
3736

doc/source/commands/system_create.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ SYNOPSIS
1212
1313
kiwi-ng [global options] service <command> [<args>]
1414
15-
kiwi-ng system create -h | --help
15+
kiwi-ng system create --help
1616
kiwi-ng system create --root=<directory> --target-dir=<directory>
1717
[--signing-key=<key-file>...]
18-
kiwi-ng system create help
1918
2019
.. _db_kiwi_system_create_desc:
2120

doc/source/commands/system_prepare.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
1111
kiwi-ng [global options] service <command> [<args>]
1212
13-
kiwi-ng system prepare -h | --help
13+
kiwi-ng system prepare --help
1414
kiwi-ng system prepare --description=<directory> --root=<directory>
1515
[--allow-existing-root]
1616
[--clear-cache]
@@ -29,7 +29,6 @@ SYNOPSIS
2929
[--set-type-attr=<attribute=value>...]
3030
[--set-release-version=<version>]
3131
[--signing-key=<key-file>...]
32-
kiwi-ng system prepare help
3332
3433
.. _db_kiwi_system_prepare_desc:
3534

0 commit comments

Comments
 (0)