clan-cli: shell completion for bash, zsh, fish

This commit is contained in:
DavHau 2023-07-21 01:08:11 +02:00 committed by Jörg Thalheim
parent 1e5cce99a9
commit af7e4d7bb9
4 changed files with 37 additions and 12 deletions

View File

@ -1,6 +1,8 @@
# !/usr/bin/env python3
import argparse
import argcomplete
import clan_admin
@ -12,4 +14,6 @@ def clan() -> None:
# init clan admin
parser_admin = subparsers.add_parser("admin")
clan_admin.make_parser(parser_admin)
argcomplete.autocomplete(parser)
parser.parse_args()

View File

@ -1,20 +1,21 @@
{
pkgs ? import <nixpkgs> {},
lib ? pkgs.lib,
python3 ? pkgs.python3,
ruff ? pkgs.ruff,
runCommand ? pkgs.runCommand,
}: let
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
, python3 ? pkgs.python3
, ruff ? pkgs.ruff
, runCommand ? pkgs.runCommand
, installShellFiles ? pkgs.installShellFiles
,
}:
let
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
name = pyproject.project.name;
src = lib.cleanSource ./.;
dependencies = lib.attrValues {
# inherit (python3.pkgs)
# some-package
# ;
inherit (python3.pkgs)
argcomplete
;
};
devDependencies = lib.attrValues {
@ -34,15 +35,22 @@
format = "pyproject";
nativeBuildInputs = [
python3.pkgs.setuptools
installShellFiles
];
propagatedBuildInputs =
dependencies
++ [ ];
passthru.tests = { inherit check; };
passthru.devDependencies = devDependencies;
postInstall = ''
installShellCompletion --bash --name clan \
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell bash clan)
installShellCompletion --fish --name clan.fish \
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell fish clan)
'';
};
checkPython = python3.withPackages (ps: devDependencies);
checkPython = python3.withPackages (ps: devDependencies ++ dependencies);
check = runCommand "${name}-check" { } ''
cp -r ${src} ./src

View File

@ -32,6 +32,10 @@ ignore_missing_imports = true
module = "pytest.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "argcomplete.*"
ignore_missing_imports = true
[tool.ruff]
line-length = 88

View File

@ -41,6 +41,15 @@ let
export PATH="$tmp_path/bin:${checkScript}/bin:$PATH"
export PYTHONPATH="$repo_root:$tmp_path/${pythonWithDeps.sitePackages}"
export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}"
mkdir -p \
$tmp_path/share/fish/vendor_completions.d \
$tmp_path/share/bash-completion/completions \
$tmp_path/share/zsh/site-functions
register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish
register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan
'';
};
in