Add first shell command

This commit is contained in:
Frédéric Guillot 2016-08-25 16:20:58 -04:00
parent 539e87b5d9
commit c0b24963b3
6 changed files with 104 additions and 0 deletions

56
almanachclient/shell.py Normal file
View File

@ -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:]))

View File

View File

@ -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')

18
almanachclient/version.py Normal file
View File

@ -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()

View File

@ -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

View File

@ -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