Skip to content

Commit

Permalink
feat: Add completion generation (#25)
Browse files Browse the repository at this point in the history
* feat: Add completion generation

* chore(README): Add documentation about shell auto completion

* chore(README): Fix title

---------

Co-authored-by: Laurent Corbes <laurent.corbes@enix.fr>
  • Loading branch information
lperdereau and lcaflc authored Dec 31, 2024
1 parent ef0db43 commit 7161f93
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ It is highly recommended to setup a dedicated user for the tool usage. You shoul
If you plan to use `pvecontrol` in read only mode to fetch cluster informations you can limit user with only `PVEAuditor` on Path `/` Permissions. This is the minimum permissions needed by `pvecontrol` to work.
For other operations on VMs it is recommended to grant `PVEVMAdmin` on Path `/`. This allows start, stop, migrate, ...

Once you have setup your management user for `pvecontrol` you can generate your configuration file. Default configuration template with all options is available (here)[https://github.com/enix/pvecontrol/blob/dev/src/pvecontrol/config_default.yaml].
Once you have setup your management user for `pvecontrol` you can generate your configuration file. Default configuration template with all options is available [here](https://github.com/enix/pvecontrol/blob/dev/src/pvecontrol/config_default.yaml).

You can use shell commands on cluster fields user and password like `user: $(<command>)` this allow you to user external software to get your secrets.

Use this file to build your own configuration file or the above exemple:

```yaml
---

Expand Down Expand Up @@ -128,6 +129,18 @@ INFO:root:Proxmox cluster: my-test-cluster

If this works, you're ready to go

Shell Auto Completion
---

`pvecontrol` provide an auto completion helper to automatically generate configuration for your prefered shell. It support curently `bash`,`zsh` and `tcsh`. The following exemple must be adapted to your own environment:

```shell
# bash
$ pvecontrol --print-completion bash > "${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions/pvecontrol"
# zsh
$ pvecontrol --print-completion zsh > "${HOME}/.zsh/completions/_pvecontrol"
```

Development
---

Expand Down
24 changes: 13 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
prettytable
humanize
confuse
pyyaml
urllib3
# proxmoxer depdends
proxmoxer>=2.0.1
requests
requests_toolbelt
openssh_wrapper
paramiko
prettytable
humanize
confuse
pyyaml
urllib3
shtab

# proxmoxer depdends
proxmoxer>=2.0.1
requests
requests_toolbelt
openssh_wrapper
paramiko
4 changes: 4 additions & 0 deletions src/pvecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import subprocess
import urllib3
import shtab

from pvecontrol import actions, node, vm, task, storage
from pvecontrol.cluster import PVECluster
Expand Down Expand Up @@ -147,6 +148,9 @@ def _parser():
parser_test = subparsers.add_parser("_test")
parser_test.set_defaults(func=action_test)

# shell autocomplete generation
shtab.add_argument_to(parser, ["-s", "--print-completion"])

return parser.parse_args()


Expand Down

0 comments on commit 7161f93

Please sign in to comment.