diff --git a/pkgs/clan-cli/clan.py b/pkgs/clan-cli/clan.py index 8fcdf0c7..7c34a51a 100755 --- a/pkgs/clan-cli/clan.py +++ b/pkgs/clan-cli/clan.py @@ -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() diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 59d2fa46..db65e551 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -1,20 +1,21 @@ -{ - pkgs ? import {}, - - lib ? pkgs.lib, - python3 ? pkgs.python3, - ruff ? pkgs.ruff, - runCommand ? pkgs.runCommand, -}: let +{ pkgs ? import { } +, 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 diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index f395f23d..33d3eb4f 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -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 diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index 2b7b0748..9df8cbe8 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -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