Skip to content

Commit 6ca82a6

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 1a27b45 commit 6ca82a6

33 files changed

+1456
-1214
lines changed

Makefile

+3-13
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

+86
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

+1-2
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

+1-2
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

+9-41
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

+1-2
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

+1-2
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

+1-2
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

+1-2
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

+1-2
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

doc/source/commands/system_update.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ SYNOPSIS
1010
1111
kiwi-ng [global options] service <command> [<args>]
1212
13-
kiwi-ng system update -h | --help
13+
kiwi-ng system update --help
1414
kiwi-ng system update --root=<directory>
1515
[--add-package=<name>...]
1616
[--delete-package=<name>...]
17-
kiwi-ng system update help
1817
1918
.. _db_kiwi_system_update_desc:
2019

doc/source/conf.py

-17
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@
3535
'sphinx_rtd_theme'
3636
]
3737

38-
docopt_ignore = [
39-
'kiwi.cli',
40-
'kiwi.tasks.system_build',
41-
'kiwi.tasks.system_prepare',
42-
'kiwi.tasks.system_update',
43-
'kiwi.tasks.system_create',
44-
'kiwi.tasks.result_list',
45-
'kiwi.tasks.result_bundle',
46-
'kiwi.tasks.image_resize',
47-
'kiwi.tasks.image_info'
48-
]
49-
50-
def remove_module_docstring(app, what, name, obj, options, lines):
51-
if what == "module" and name in docopt_ignore:
52-
del lines[:]
53-
5438
def prologReplace(app, docname, source):
5539
result = source[0]
5640
for key in app.config.prolog_replacements:
@@ -60,7 +44,6 @@ def prologReplace(app, docname, source):
6044
def setup(app):
6145
app.add_config_value('prolog_replacements', {}, True)
6246
app.connect('source-read', prologReplace)
63-
app.connect("autodoc-process-docstring", remove_module_docstring)
6447

6548

6649
prolog_replacements = {

doc/source/contributing.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ Create a Python Virtual Development Environment
6262
-----------------------------------------------
6363

6464
The following commands initializes and activates a development
65-
environment for Python 3:
65+
environment for the current default Python version:
6666

6767
.. code:: shell-session
6868
6969
$ poetry install
7070
71+
.. note::
72+
73+
To create the python virtual env for another version of
74+
Python, e.g. 3.11, call the following prior the poetry install
75+
::
76+
77+
$ poetry env use python3.11
78+
7179
The command above automatically creates the application script
7280
called :command:`kiwi-ng`, which allows you to run {kiwi} from the
7381
Python sources inside the virtual environment using Poetry:
@@ -76,7 +84,6 @@ Python sources inside the virtual environment using Poetry:
7684
7785
$ poetry run kiwi-ng --help
7886
79-
8087
Running the Unit Tests
8188
----------------------
8289

0 commit comments

Comments
 (0)