diff --git a/doc/manpages/qubes-prefs.rst b/doc/manpages/qubes-prefs.rst index 7ad6d27b..867a2f13 100644 --- a/doc/manpages/qubes-prefs.rst +++ b/doc/manpages/qubes-prefs.rst @@ -43,6 +43,10 @@ Options Ignored; for compatibility with older scripts. +.. option:: --version + + Show program's version number and exit + Common properties ================= diff --git a/doc/manpages/qvm-backup-restore.rst b/doc/manpages/qvm-backup-restore.rst index 84980fcc..3ecb891e 100644 --- a/doc/manpages/qvm-backup-restore.rst +++ b/doc/manpages/qvm-backup-restore.rst @@ -108,6 +108,10 @@ Options on the standard output. The log will be colored red if the standard output is a terminal. +.. option:: --version + + Show program's version number and exit + Authors ======= | Joanna Rutkowska diff --git a/doc/manpages/qvm-backup.rst b/doc/manpages/qvm-backup.rst index 7126add3..0b48b73e 100644 --- a/doc/manpages/qvm-backup.rst +++ b/doc/manpages/qvm-backup.rst @@ -68,6 +68,10 @@ Options Do not ask for confirmation +.. option:: --version + + Show program's version number and exit + Arguments --------- diff --git a/doc/manpages/qvm-check.rst b/doc/manpages/qvm-check.rst index ec7f5068..53dd186a 100644 --- a/doc/manpages/qvm-check.rst +++ b/doc/manpages/qvm-check.rst @@ -56,6 +56,10 @@ Options Determine if (any of given) VM can reach network +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-clone.rst b/doc/manpages/qvm-clone.rst index c3caacfb..34acfecb 100644 --- a/doc/manpages/qvm-clone.rst +++ b/doc/manpages/qvm-clone.rst @@ -51,6 +51,10 @@ Options Increase verbosity +.. option:: --version + + Show program's version number and exit + Authors ------- | Joanna Rutkowska diff --git a/doc/manpages/qvm-create.rst b/doc/manpages/qvm-create.rst index b0a6370f..e1d88648 100644 --- a/doc/manpages/qvm-create.rst +++ b/doc/manpages/qvm-create.rst @@ -80,6 +80,10 @@ Options Specify the pool to use for the specific volume +.. option:: --version + + Show program's version number and exit + Qube classes ------------ diff --git a/doc/manpages/qvm-device.rst b/doc/manpages/qvm-device.rst index 38257ed6..b015c1d8 100644 --- a/doc/manpages/qvm-device.rst +++ b/doc/manpages/qvm-device.rst @@ -35,6 +35,10 @@ Options list device classes +.. option:: --version + + Show program's version number and exit + Commands ======== diff --git a/doc/manpages/qvm-features.rst b/doc/manpages/qvm-features.rst index 29cf35de..9febd0f2 100644 --- a/doc/manpages/qvm-features.rst +++ b/doc/manpages/qvm-features.rst @@ -27,6 +27,10 @@ Options Unset the feature. +.. option:: --version + + Show program's version number and exit + Description ----------- diff --git a/doc/manpages/qvm-firewall.rst b/doc/manpages/qvm-firewall.rst index f2cc8123..f84a7ce3 100644 --- a/doc/manpages/qvm-firewall.rst +++ b/doc/manpages/qvm-firewall.rst @@ -37,6 +37,10 @@ Options in combination with `list` action, print raw rules +.. option:: --version + + Show program's version number and exit + Actions description ------------------- diff --git a/doc/manpages/qvm-kill.rst b/doc/manpages/qvm-kill.rst index b5345730..fd8d1a9e 100644 --- a/doc/manpages/qvm-kill.rst +++ b/doc/manpages/qvm-kill.rst @@ -32,6 +32,10 @@ Options decrease verbosity +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-ls.rst b/doc/manpages/qvm-ls.rst index d82034d5..4632add4 100644 --- a/doc/manpages/qvm-ls.rst +++ b/doc/manpages/qvm-ls.rst @@ -61,6 +61,10 @@ General options No spinner today. +.. option:: --version + + Show program's version number and exit + Formatting options ------------------ diff --git a/doc/manpages/qvm-pause.rst b/doc/manpages/qvm-pause.rst index b561eb93..ecaba6a8 100644 --- a/doc/manpages/qvm-pause.rst +++ b/doc/manpages/qvm-pause.rst @@ -31,6 +31,10 @@ Options Exclude the qube from :option:`--all`. +.. option:: --version + + Show program's version number and exit + Notes ----- diff --git a/doc/manpages/qvm-pool.rst b/doc/manpages/qvm-pool.rst index 49d04039..629801c6 100644 --- a/doc/manpages/qvm-pool.rst +++ b/doc/manpages/qvm-pool.rst @@ -38,6 +38,10 @@ Options Increase verbosity +.. option:: --version + + Show program's version number and exit + Commands -------- diff --git a/doc/manpages/qvm-prefs.rst b/doc/manpages/qvm-prefs.rst index 7e688137..ea531d00 100644 --- a/doc/manpages/qvm-prefs.rst +++ b/doc/manpages/qvm-prefs.rst @@ -43,6 +43,10 @@ Options Ignored; for compatibility with older scripts. +.. option:: --version + + Show program's version number and exit + Property values =============== diff --git a/doc/manpages/qvm-remove.rst b/doc/manpages/qvm-remove.rst index 47c55460..ad1472c9 100644 --- a/doc/manpages/qvm-remove.rst +++ b/doc/manpages/qvm-remove.rst @@ -44,6 +44,10 @@ Options decrease verbosity +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-run.rst b/doc/manpages/qvm-run.rst index 77ed7361..75a8063c 100644 --- a/doc/manpages/qvm-run.rst +++ b/doc/manpages/qvm-run.rst @@ -138,6 +138,10 @@ Options Treat *COMMAND* as a command to be executed directly, not passed to a shell. This is default if there are additional arguments to `qvm-run`. +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-service.rst b/doc/manpages/qvm-service.rst index fecab262..c62c0c81 100644 --- a/doc/manpages/qvm-service.rst +++ b/doc/manpages/qvm-service.rst @@ -41,6 +41,10 @@ Options decrease verbosity +.. option:: --version + + Show program's version number and exit + Supported services ================== diff --git a/doc/manpages/qvm-shutdown.rst b/doc/manpages/qvm-shutdown.rst index f238444a..9427fdc4 100644 --- a/doc/manpages/qvm-shutdown.rst +++ b/doc/manpages/qvm-shutdown.rst @@ -50,6 +50,10 @@ Options don't really shutdown or kill the domains; useful with :option:`--wait` +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-start-daemon.rst b/doc/manpages/qvm-start-daemon.rst index 922d8329..4ed7bb19 100644 --- a/doc/manpages/qvm-start-daemon.rst +++ b/doc/manpages/qvm-start-daemon.rst @@ -76,6 +76,10 @@ Options Notify running instance in --watch mode about changed monitor layout +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-start.rst b/doc/manpages/qvm-start.rst index 46ff2d08..c778014d 100644 --- a/doc/manpages/qvm-start.rst +++ b/doc/manpages/qvm-start.rst @@ -72,6 +72,10 @@ Options Temporarily attach Windows tools CDROM to the domain. This is equivalent with `--cdrom=dom0:/usr/lib/qubes/qubes-windows-tools.iso`. +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-tags.rst b/doc/manpages/qvm-tags.rst index f3ac8915..ed3e19ce 100644 --- a/doc/manpages/qvm-tags.rst +++ b/doc/manpages/qvm-tags.rst @@ -35,6 +35,10 @@ Options Decrease verbosity. +.. option:: --version + + Show program's version number and exit + Commands -------- diff --git a/doc/manpages/qvm-template.rst b/doc/manpages/qvm-template.rst index 87f062bf..ce72b892 100644 --- a/doc/manpages/qvm-template.rst +++ b/doc/manpages/qvm-template.rst @@ -75,6 +75,10 @@ Options Decrease verbosity. +.. option:: --version + + Show program's version number and exit + Commands -------- diff --git a/doc/manpages/qvm-unpause.rst b/doc/manpages/qvm-unpause.rst index 12a9ddad..72d1e2c0 100644 --- a/doc/manpages/qvm-unpause.rst +++ b/doc/manpages/qvm-unpause.rst @@ -40,6 +40,10 @@ Options Exclude the qube from :option:`--all`. +.. option:: --version + + Show program's version number and exit + Authors ------- diff --git a/doc/manpages/qvm-volume.rst b/doc/manpages/qvm-volume.rst index 81433eb8..5f1fee82 100644 --- a/doc/manpages/qvm-volume.rst +++ b/doc/manpages/qvm-volume.rst @@ -28,6 +28,10 @@ Options Decrease verbosity. +.. option:: --version + + Show program's version number and exit + Commands -------- diff --git a/qubesadmin/backup/dispvm.py b/qubesadmin/backup/dispvm.py index 47307dc4..15a45678 100644 --- a/qubesadmin/backup/dispvm.py +++ b/qubesadmin/backup/dispvm.py @@ -107,6 +107,7 @@ class RestoreInDisposableVM: 'auto_close': Option(('--auto-close',), skip), # make the verification easier, those don't really matter 'help': Option(('--help', '-h'), skip), + 'version': Option(('--version',), skip), 'force_root': Option(('--force-root',), skip), } diff --git a/qubesadmin/tools/__init__.py b/qubesadmin/tools/__init__.py index 608b1a23..d051faf9 100644 --- a/qubesadmin/tools/__init__.py +++ b/qubesadmin/tools/__init__.py @@ -25,6 +25,7 @@ import argparse import importlib +import importlib.metadata import logging import os import subprocess @@ -342,9 +343,14 @@ class QubesArgumentParser(argparse.ArgumentParser): ``--force-root`` (optional, ignored, help is suppressed) ``--offline-mode`` do not talk to hypervisor (help is suppressed) ``--verbose`` and ``--quiet`` + + Calling program should set the ``version`` argument for ``--version`` option + The default is extracted from `qubesadmin` package information. + Setting ``version`` argument to '' will disable ``--version`` option. ''' - def __init__(self, vmname_nargs=None, show_forceroot=False, **kwargs): + def __init__(self, vmname_nargs=None, show_forceroot=False, version=None, \ + **kwargs): super().__init__(add_help=False, **kwargs) @@ -369,6 +375,17 @@ def __init__(self, vmname_nargs=None, show_forceroot=False, **kwargs): self.add_argument('--help', '-h', action=SubParsersHelpAction, help='show this help message and exit') + if version is not None: + self.version = version + else: + _metadata_ = importlib.metadata.metadata('qubesadmin') + self.version = '{} ({}) {}'.format(os.path.basename(sys.argv[0]), \ + _metadata_['summary'], _metadata_['version']) + self.version += '\nCopyright (C) {}'.format(_metadata_['author']) + self.version += '\nLicense: {}'.format(_metadata_['license']) + if self.version != '': + self.add_argument('--version', action='version') + if self._vmname_nargs in [argparse.ZERO_OR_MORE, argparse.ONE_OR_MORE]: vm_name_group = VmNameGroup(self, required=(self._vmname_nargs diff --git a/qubesadmin/tools/dochelpers.py b/qubesadmin/tools/dochelpers.py index 3a24f9fd..55be0629 100644 --- a/qubesadmin/tools/dochelpers.py +++ b/qubesadmin/tools/dochelpers.py @@ -188,7 +188,8 @@ def visit_section(self, node): sub_cmd, args, self.document) node.walkabout(options_visitor) options_visitor.check_undocumented_arguments( - {'--help', '--quiet', '--verbose', '-h', '-q', '-v'}) + {'--help', '--quiet', '--verbose', '-h', '-q', '-v', \ + '--version'}) del self.sub_commands[cmd] except KeyError: raise sphinx.errors.SphinxError(