From c0b24963b38352c07b61c1fb3c7be626f4be7b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Thu, 25 Aug 2016 16:20:58 -0400 Subject: [PATCH] Add first shell command --- almanachclient/shell.py | 56 ++++++++++++++++++++++++++++++++ almanachclient/v1/__init__.py | 0 almanachclient/v1/version_cli.py | 25 ++++++++++++++ almanachclient/version.py | 18 ++++++++++ requirements.txt | 1 + setup.cfg | 4 +++ 6 files changed, 104 insertions(+) create mode 100644 almanachclient/shell.py create mode 100644 almanachclient/v1/__init__.py create mode 100644 almanachclient/v1/version_cli.py create mode 100644 almanachclient/version.py diff --git a/almanachclient/shell.py b/almanachclient/shell.py new file mode 100644 index 0000000..baf9a88 --- /dev/null +++ b/almanachclient/shell.py @@ -0,0 +1,56 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +""" +Command-line interface to the OpenStack Almanach API. +""" + +import sys + +from cliff import app +from cliff import commandmanager + +from almanachclient import version +from almanachclient.v1 import version_cli + + +class AlmanachCommandManager(commandmanager.CommandManager): + SHELL_COMMANDS = { + "version": version_cli.CliVersionShow, + } + + def load_commands(self, namespace): + for name, command_class in self.SHELL_COMMANDS.items(): + self.add_command(name, command_class) + + +class AlmanachApp(app.App): + + def __init__(self): + super(AlmanachApp, self).__init__( + description='Almanach command line client', + version=version.__version__, + command_manager=AlmanachCommandManager(None), + deferred_help=True, + ) + + +def main(args=None): + if args is None: + args = sys.argv[1:] + return AlmanachApp().run(args) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/almanachclient/v1/__init__.py b/almanachclient/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/almanachclient/v1/version_cli.py b/almanachclient/v1/version_cli.py new file mode 100644 index 0000000..c1dfe68 --- /dev/null +++ b/almanachclient/v1/version_cli.py @@ -0,0 +1,25 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +from cliff.command import Command + + +from almanachclient import version + + +class CliVersionShow(Command): + """Show the client version number""" + + def take_action(self, parsed_args): + self.app.stdout.write(version.__version__ + '\n') diff --git a/almanachclient/version.py b/almanachclient/version.py new file mode 100644 index 0000000..e58667d --- /dev/null +++ b/almanachclient/version.py @@ -0,0 +1,18 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +import pbr.version + + +__version__ = pbr.version.VersionInfo('almanachclient').version_string() diff --git a/requirements.txt b/requirements.txt index 95d0fe8..09a66dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ # process, which may cause wedges in the gate later. pbr>=1.6 # Apache-2.0 +cliff>1.16.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 62b4663..3240ae9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,6 +23,10 @@ classifier = packages = almanachclient +[entry_points] +console_scripts = + almanach = almanachclient.shell:main + [build_sphinx] source-dir = doc/source build-dir = doc/build