Skip to content
Snippets Groups Projects
Commit 3d509fa6 authored by Mario Limonciello's avatar Mario Limonciello Committed by Mario Limonciello
Browse files

Generate bash-completion and zsh-completion using shtab

parent 9a3b379b
No related branches found
No related tags found
1 merge request!164Enable bash completion and change some meson options
...@@ -51,6 +51,7 @@ pre_commit: ...@@ -51,6 +51,7 @@ pre_commit:
build_stable: build_stable:
variables: variables:
JOB_DEPS: argparse-manpage JOB_DEPS: argparse-manpage
python3-shtab
extends: extends:
- .install-deps - .install-deps
script: script:
......
...@@ -67,6 +67,18 @@ address_sanitizer = get_option('b_sanitize') == 'address' or \ ...@@ -67,6 +67,18 @@ address_sanitizer = get_option('b_sanitize') == 'address' or \
get_option('b_sanitize') == 'address,undefined' or \ get_option('b_sanitize') == 'address,undefined' or \
get_option('b_sanitize') == 'leak' get_option('b_sanitize') == 'leak'
python = import('python')
python3 = python.find_installation('python3')
have_shtab = run_command(
[python3, '-c', 'import shtab'], check: false).returncode() == 0
if not have_shtab
warning('''python3-shtab not found''')
endif
bashcomp = dependency('bash-completion', required: get_option('bashcomp').disable_auto_if(not have_shtab))
zshcomp = have_shtab and get_option('zshcomp') != ''
subdir('src') subdir('src')
subdir('data') subdir('data')
...@@ -80,6 +92,9 @@ if get_option('gtk_doc') ...@@ -80,6 +92,9 @@ if get_option('gtk_doc')
subdir('docs') subdir('docs')
endif endif
python = import('python')
python3 = python.find_installation('python3')
if get_option('tests') if get_option('tests')
# Python 3 required modules # Python 3 required modules
python3_required_modules = ['dbusmock', 'gi'] python3_required_modules = ['dbusmock', 'gi']
...@@ -89,8 +104,6 @@ if get_option('tests') ...@@ -89,8 +104,6 @@ if get_option('tests')
'UMockdev': '1.0', 'UMockdev': '1.0',
} }
python = import('python')
python3 = python.find_installation('python3')
foreach p : python3_required_modules foreach p : python3_required_modules
# Source: https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported # Source: https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported
script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)' script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)'
......
...@@ -18,3 +18,11 @@ option('manpage', ...@@ -18,3 +18,11 @@ option('manpage',
description: 'generate powerprofilesctl man page', description: 'generate powerprofilesctl man page',
type: 'feature', type: 'feature',
value: 'auto') value: 'auto')
option('bashcomp',
description: 'generate bash completion',
type: 'feature',
value: 'auto')
option('zshcomp',
description: 'path for zsh completion file',
type: 'string',
value: '')
...@@ -146,3 +146,35 @@ if argparse_manpage.found() ...@@ -146,3 +146,35 @@ if argparse_manpage.found()
output: 'powerprofilesctl.1', output: 'powerprofilesctl.1',
)) ))
endif endif
generate_completion = [python3, powerprofilesctl, '--print-completion']
if bashcomp.found()
completions_dir = bashcomp.get_variable(pkgconfig: 'completionsdir',
pkgconfig_define: bashcomp.version().version_compare('>= 2.10') ?
['datadir', get_option('datadir')] : ['prefix', prefix],
)
custom_target('bash-completion',
output: 'powerprofilesctl',
command: [
generate_completion,
'bash',
],
capture: true,
install: true,
install_dir: completions_dir,
)
endif
if zshcomp
custom_target('zsh-completion',
output: '_powerprofilesctl',
command: [
generate_completion,
'zsh',
],
capture: true,
install: true,
install_dir: get_option('zshcomp'),
)
endif
...@@ -190,6 +190,13 @@ def get_parser(): ...@@ -190,6 +190,13 @@ def get_parser():
) )
parser_version.set_defaults(func=_version) parser_version.set_defaults(func=_version)
try:
import shtab # pylint: disable=import-outside-toplevel
shtab.add_argument_to(parser, ["-s", "--print-completion"]) # magic!
except ImportError:
pass
return parser return parser
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment