Commit a47d0315 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

[toolchains] Click implementation of toolchains commands

Reimplement toolchains existing
commands using  plugin-based command line mechanism (Click).
parent 9530537e
......@@ -26,114 +26,200 @@
###############################################################################
"""Usage:
%(prog)s toolchains list [--remote]
%(prog)s toolchains path [<name>]...
%(prog)s toolchains edit <name>...
%(prog)s toolchains check [<name>]...
%(prog)s toolchains pull [--force] [<name>]...
%(prog)s toolchains push [--force] [--dry-run] [<name>]...
%(prog)s toolchains diff <name>
%(prog)s toolchains status
%(prog)s toolchains create <name>...
%(prog)s toolchains version <name>
%(prog)s toolchains fork <src> <dst>
%(prog)s toolchains rm [--remote] <name>...
%(prog)s toolchains draw [--path=<dir>] [<name>]...
%(prog)s toolchains --help
Commands:
list Lists all the toolchains available on the platform
path Displays local path of toolchains files
edit Edit local toolchain file
check Checks a local toolchain for validity
pull Downloads the specified toolchains from the server
push Uploads toolchains to the server
diff Shows changes between the local toolchain and the remote version
status Shows (editing) status for all available toolchains
create Creates a new local toolchain
version Creates a new version of an existing toolchain
fork Forks a local toolchain
rm Deletes a local toolchain (unless --remote is specified)
draw Creates a visual representation of the toolchain
Options:
--force Performs operation regardless of conflicts
--dry-run Doesn't really perform the task, just comments what would do
--remote Only acts on the remote copy of the toolchain
--path=<dir> Use path to write files to disk (instead of the current
directory)
--help Display this screen
"""
import click
from . import common
def process(args):
if args['list']:
if args['--remote']:
with common.make_webapi(args['config']) as webapi:
return common.display_remote_list(webapi, 'toolchain')
@click.group()
@click.pass_context
def toolchains(ctx):
"""toolchains commands"""
pass
@toolchains.command()
@click.option('--remote', help='Only acts on the remote copy of the list.',
is_flag=True)
@click.pass_context
def list(ctx, remote):
'''Lists all the toolchains available on the platform.
To list all existing toolchains on your local prefix:
$ beat toolchains list
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.display_remote_list(webapi, 'toolchain')
else:
return common.display_local_list(args['config'].path, 'toolchain')
elif args['path']:
return common.display_local_path(args['config'].path, 'toolchain', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, args['config'].editor, 'toolchain', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'toolchain', args['<name>'])
elif args['pull']:
with common.make_webapi(args['config']) as webapi:
status, downloaded = common.pull(webapi, args['config'].path,
'toolchain', args['<name>'], ['declaration', 'description'],
args['--force'], indentation=0)
return status
elif args['push']:
with common.make_webapi(args['config']) as webapi:
return common.push(webapi, args['config'].path, 'toolchain',
args['<name>'], ['name', 'declaration', 'description'], {},
args['--force'], args['--dry-run'], 0)
elif args['diff']:
with common.make_webapi(args['config']) as webapi:
return common.diff(webapi, args['config'].path, 'toolchain',
args['<name>'][0], ['declaration', 'description'])
elif args['status']:
with common.make_webapi(args['config']) as webapi:
return common.status(webapi, args['config'].path, 'toolchain')[0]
elif args['create']:
return common.create(args['config'].path, 'toolchain', args['<name>'])
elif args['version']:
return common.new_version(args['config'].path, 'toolchain',
args['<name>'][0])
elif args['fork']:
return common.fork(args['config'].path, 'toolchain',
args['<src>'], args['<dst>'])
elif args['rm']:
if args['--remote']:
with common.make_webapi(args['config']) as webapi:
return common.delete_remote(webapi, 'toolchain', args['<name>'])
return common.display_local_list(ctx.meta['config'].path, 'toolchain')
@toolchains.command()
@click.argument('names', nargs=-1)
@click.pass_context
def path(ctx, names):
'''Displays local path of toolchain files
Example:
$ beat toolchains path xxx
'''
return common.display_local_path(ctx.meta['config'].path, 'toolchain', names)
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def edit(ctx, name):
'''Edit local toolchain file
Example:
$ beat toolchains edit xxx
'''
return common.edit_local_file(ctx.meta['config'].path,
ctx.meta['config'].editor, 'toolchain',
name)
@toolchains.command()
@click.argument('name', nargs=1)
@click.pass_context
def check(ctx, name):
'''Checks a local toolchain for validity.
$ beat toolchains check xxx
'''
return common.check(ctx.meta['config'].path, 'toolchain', name)
@toolchains.command()
@click.argument('name', nargs=1)
@click.option('--force', help='Force',
is_flag=True)
@click.pass_context
def pull(ctx, name, force):
'''Downloads the specified toolchains from the server.
$ beat toolchains pull xxx.
'''
with common.make_webapi(ctx.meta['config']) as webapi:
status, downloaded = common.pull(
webapi, ctx.meta['config'].path, 'toolchain', name,
['declaration', 'description'], force, indentation=0)
return status
@toolchains.command()
@click.argument('name', nargs=1)
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.option('--dry-run', help="Doesn't really perform the task, just "
"comments what would do", is_flag=True)
@click.pass_context
def push(ctx, name, force, dry_run):
'''Uploads toolchains to the server
Example:
$ beat toolchains push --dry-run yyy
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.push(
webapi, ctx.meta['config'].path, 'toolchain', name,
['name', 'declaration', 'description'], {}, force, dry_run, 0
)
@toolchains.command()
@click.argument('name', nargs=1)
@click.pass_context
def diff(ctx, name):
'''Shows changes between the local dataformat and the remote version
Example:
$ beat toolchains diff xxx
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.diff(webapi, ctx.meta['config'].path, 'toolchain',
name, ['declaration', 'description'])
@toolchains.command()
@click.pass_context
def status(ctx):
'''Shows (editing) status for all available toolchains
Example:
$ beat toolchains status
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.status(webapi, ctx.meta['config'].path, 'toolchain')[0]
@toolchains.command()
@click.argument('name', nargs=1)
@click.pass_context
def create(ctx, name):
'''Creates a new local toolchain.
$ beat toolchains create xxx
'''
return common.create(ctx.meta['config'].path, 'toolchain', [name])
@toolchains.command()
@click.argument('name', nargs=1)
@click.pass_context
def version(ctx, name):
'''Creates a new version of an existing toolchain.
$ beat toolchains version xxx
'''
return common.new_version(ctx.meta['config'].path, 'toolchain', name)
@toolchains.command()
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.pass_context
def fork(ctx, src, dst):
'''Forks a local toolchain.
$ beat toolchains fork xxx yyy
'''
return common.fork(ctx.meta['config'].path, 'toolchain', src, dst)
@toolchains.command()
@click.argument('name', nargs=1)
@click.pass_context
def rm(ctx, name):
'''Deletes a local toolchain (unless --remote is specified).
$ beat toolchains rm xxx
'''
if ctx.meta['--remote']:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.delete_remote(webapi, 'toolchain', name)
else:
return common.delete_local(args['config'].path, 'toolchain',
args['<name>'])
return common.delete_local(ctx.meta['config'].path, 'toolchain', name)
elif args['draw']:
return common.dot_diagram(args['config'].path, 'toolchain', args['<name>'],
args['--path'], [])
# Should not happen
logger.error("unrecognized `toolchains' subcommand")
return 1
@toolchains.command()
@click.argument('name', nargs=1)
@click.option('--path', help='Use path to write files to disk (instead of the '
'current directory)', type=click.Path())
@click.pass_context
def draw(ctx, name, path):
return common.dot_diagram(
ctx.meta['config'].path, 'toolchain', name, path, []
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment