From 793ac29e4041f79245af50caf215658b52223e25 Mon Sep 17 00:00:00 2001 From: Tommy Wang Date: Mon, 5 Dec 2016 14:18:29 -0600 Subject: [PATCH] add version and check-update --- aws_workflow/cli.py | 53 ++++++++++++++++++++++++++++++++++------- aws_workflow/utils.py | 7 ++++++ aws_workflow/version.py | 1 + 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 aws_workflow/version.py diff --git a/aws_workflow/cli.py b/aws_workflow/cli.py index d39dcf5..3348ee0 100644 --- a/aws_workflow/cli.py +++ b/aws_workflow/cli.py @@ -15,7 +15,9 @@ get_region, make_pass_decorator, parse_query, + set_version, ) +from .version import __version__ log = logging.getLogger() @@ -106,14 +108,14 @@ def script_filter(query, wf, default_command): @cli.command('set-profile') @click.argument('profile') @pass_wf -def set_profile(profile, wf): +def do_set_profile(profile, wf): log.info('setting profile to %s' % profile) wf.settings['profile'] = profile @cli.command('clear-cache') @pass_wf -def clear_cache(wf): +def do_clear_cache(wf): log.info('cache cleared') def _filter(n): return not n.endswith('.pid') @@ -122,19 +124,25 @@ def _filter(n): @cli.command('open-help') @pass_wf -def clear_cache(wf): +def do_open_help(wf): wf.open_help() @cli.command('update-workflow') @pass_wf -def update_workflow(wf): +def do_update_workflow(wf): if wf.start_update(): log.info('updating alfred') else: log.info('no update found') +@cli.command('check-update') +@pass_wf +def do_check_update(wf): + wf.check_update(force=True) + + @cli.command('background') @click.option('--data_name', envvar='WF_CACHE_DATA_NAME') @click.argument('command') @@ -188,7 +196,7 @@ def list_profiles(query, wf, complete): def clear_cache(query, wf): '''clears cache''' item = wf.add_item( - title='clear cache', + title='clear-cache', subtitle='clears cache', valid=True, arg='clear-cache', @@ -201,10 +209,11 @@ def clear_cache(query, wf): @wf_commands.command('help') @click.argument('query', required=False) @pass_wf -def help(query, wf): +def open_help(query, wf): '''opens help in browser''' item = wf.add_item( - title='open help', + title='help', + subtitle='opens help in browser', valid=True, arg='open-help', autocomplete='help') @@ -212,6 +221,34 @@ def help(query, wf): wf.send_feedback() +@wf_commands.command('check-update') +@click.argument('query', required=False) +@pass_wf +def check_update(query, wf): + '''checks for updates''' + item = wf.add_item( + title='check-update', + subtitle='checks for updates', + valid=True, + arg='check-update', + autocomplete='check-update') + item.setvar('action', 'run-script') + wf.send_feedback() + + +@wf_commands.command('version') +@click.argument('query', required=False) +@pass_wf +@set_version +def get_version(query, wf): + '''%s''' + item = wf.add_item( + title='version', + subtitle=version, + valid=False) + wf.send_feedback() + + @root.command('+') @click.argument('query', required=False) @pass_wf @@ -326,7 +363,7 @@ def main(): wf = workflow.Workflow3( update_settings={ 'github_slug': 'twang817/aws-alfred-workflow', - 'version': 'v3.1.2', + 'version': __version__, }, help_url='https://github.com/twang817/aws-alfred-workflow/blob/master/README.md', ) diff --git a/aws_workflow/utils.py b/aws_workflow/utils.py index b877aea..9b7470a 100644 --- a/aws_workflow/utils.py +++ b/aws_workflow/utils.py @@ -5,6 +5,8 @@ import boto3 import click +from .version import __version__ + log = logging.getLogger() @@ -96,3 +98,8 @@ def autocomplete_group(wf, query, group, complete): valid=True, autocomplete=complete + item) wf.send_feedback() + + +def set_version(f): + f.__doc__ = f.__doc__ % __version__ + return f diff --git a/aws_workflow/version.py b/aws_workflow/version.py new file mode 100644 index 0000000..919ac14 --- /dev/null +++ b/aws_workflow/version.py @@ -0,0 +1 @@ +__version__ = 'v3.1.2'