diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /hacking/build_library/build_ansible/commands.py | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream/2.14.3.tar.xz ansible-core-upstream/2.14.3.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | hacking/build_library/build_ansible/commands.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hacking/build_library/build_ansible/commands.py b/hacking/build_library/build_ansible/commands.py new file mode 100644 index 0000000..8267993 --- /dev/null +++ b/hacking/build_library/build_ansible/commands.py @@ -0,0 +1,50 @@ +# coding: utf-8 +# Copyright: (c) 2019, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from abc import ABCMeta, abstractmethod, abstractproperty + + +class Command(metaclass=ABCMeta): + """ + Subcommands of :program:`build-ansible.py`. + + This defines an interface that all subcommands must conform to. :program:`build-ansible.py` + will require that these things are present in order to proceed. + """ + @staticmethod + @abstractproperty + def name(): + """Name of the subcommand. It's the string to invoked it via on the command line""" + + @staticmethod + @abstractmethod + def init_parser(add_parser): + """ + Initialize and register an argparse ArgumentParser + + :arg add_parser: function which creates an ArgumentParser for the main program. + + Implementations should first create an ArgumentParser using `add_parser` and then populate + it with the command line arguments that are needed. + + .. seealso: + `add_parser` information in the :py:meth:`ArgumentParser.add_subparsers` documentation. + """ + + @staticmethod + @abstractmethod + def main(arguments): + """ + Run the command + + :arg arguments: The **parsed** command line args + + This is the Command's entrypoint. The command line args are already parsed but from here + on, the command can do its work. + """ |