Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/manpages/qubes-prefs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Options

Ignored; for compatibility with older scripts.

.. option:: --version

Show program's version number and exit


Common properties
=================
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-backup-restore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <joanna at invisiblethingslab dot com>
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-backup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Options

Do not ask for confirmation

.. option:: --version

Show program's version number and exit

Arguments
---------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-check.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Options

Determine if (any of given) VM can reach network

.. option:: --version

Show program's version number and exit

Authors
-------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-clone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Options

Increase verbosity

.. option:: --version

Show program's version number and exit

Authors
-------
| Joanna Rutkowska <joanna at invisiblethingslab dot com>
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Options

list device classes

.. option:: --version

Show program's version number and exit

Commands
========

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Options

Unset the feature.

.. option:: --version

Show program's version number and exit

Description
-----------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-firewall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Options

in combination with `list` action, print raw rules

.. option:: --version

Show program's version number and exit


Actions description
-------------------
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-kill.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Options

decrease verbosity

.. option:: --version

Show program's version number and exit


Authors
-------
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-ls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ General options

No spinner today.

.. option:: --version

Show program's version number and exit

Formatting options
------------------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-pause.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Options

Exclude the qube from :option:`--all`.

.. option:: --version

Show program's version number and exit

Notes
-----

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-pool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Options

Increase verbosity

.. option:: --version

Show program's version number and exit

Commands
--------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-prefs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Options

Ignored; for compatibility with older scripts.

.. option:: --version

Show program's version number and exit


Property values
===============
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-remove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Options

decrease verbosity

.. option:: --version

Show program's version number and exit

Authors
-------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Options

decrease verbosity

.. option:: --version

Show program's version number and exit

Supported services
==================

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-shutdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-start-daemon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Options

Decrease verbosity.

.. option:: --version

Show program's version number and exit

Commands
--------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Options

Decrease verbosity.

.. option:: --version

Show program's version number and exit

Commands
--------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-unpause.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Options

Exclude the qube from :option:`--all`.

.. option:: --version

Show program's version number and exit

Authors
-------

Expand Down
4 changes: 4 additions & 0 deletions doc/manpages/qvm-volume.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Options

Decrease verbosity.

.. option:: --version

Show program's version number and exit

Commands
--------

Expand Down
1 change: 1 addition & 0 deletions qubesadmin/backup/dispvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
19 changes: 18 additions & 1 deletion qubesadmin/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import argparse
import importlib
import importlib.metadata
import logging
import os
import subprocess
Expand Down Expand Up @@ -342,9 +343,14 @@
``--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)

Expand All @@ -369,6 +375,17 @@
self.add_argument('--help', '-h', action=SubParsersHelpAction,
help='show this help message and exit')

if version is not None:
self.version = version

Check warning on line 379 in qubesadmin/tools/__init__.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/__init__.py#L379

Added line #L379 was not covered by tests
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
Expand Down
3 changes: 2 additions & 1 deletion qubesadmin/tools/dochelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down