-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: add
install-completions
subcommand
- Loading branch information
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
import click | ||
from plumbum import CommandNotFound, local | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
COMPLETERS_PATH = [ | ||
('bash_source', Path('/opt/homebrew/share/bash-completion/completions')), | ||
('bash_source', Path('/usr/local/share/bash-completion/completions')), | ||
('bash_source', Path('/usr/share/bash-completion/completions')) | ||
] | ||
|
||
ZSH_COMPLETERS_PATH = [] | ||
|
||
|
||
@click.group() | ||
def cli() -> None: | ||
pass | ||
|
||
|
||
@cli.command() | ||
def install_completions() -> None: | ||
""" Install shell completions for the pymobiledevice3 command """ | ||
try: | ||
pymobiledevice3 = local['pymobiledevice3'] | ||
except CommandNotFound: | ||
logger.error('pymobiledevice3 main binary could not be found in your path.') | ||
return | ||
paths_written = 0 | ||
for envvar_value, path in COMPLETERS_PATH: | ||
if not path.exists(): | ||
continue | ||
try: | ||
with local.env(_PYMOBILEDEVICE3_COMPLETE=envvar_value): | ||
logger.info(f'Installing shell completions in: {path}') | ||
(path / 'pymobiledevice3').write_text(pymobiledevice3()) | ||
paths_written += 1 | ||
except PermissionError: | ||
logger.warning( | ||
f'Got "PermissionError" trying to write into: {path}. ' | ||
'Please retry as root or change the directory permissions' | ||
) | ||
|
||
if paths_written == 0: | ||
logger.error( | ||
'No shell completions path could be found. Please consider submitting a pull request or creating an issue ' | ||
'detailing your platform and the PATH that should be added.\n' | ||
'\n' | ||
'https://github.com/doronz88/pymobiledevice3/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=' # noqa: E501 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ aiofiles | |
prompt_toolkit | ||
sslpsk-pmd3>=1.0.3;python_version<'3.13' | ||
python-pcapng>=2.1.1 | ||
plumbum |