def use(ctx, shortcut):
    """Use a shortcut."""
    git_dir = current_git_dir()

    if git_dir is None:
        output(NOT_GIT_REPO_MSG)
        exit(1)

    repo_root = os.path.dirname(git_dir)

    config = get_config(repo_root)

    try:
        use_shortcut = config.shortcuts.get(shortcut)

        while use_shortcut.extends is not None:
            base = config.shortcuts.get(use_shortcut.extends)
            use_shortcut = base.extend(use_shortcut)
    except config.shortcuts.DoesNotExist as err:
        output('{}\nAvailable shortcuts:'.format(err.message))

        for s in config.shortcuts:
            output(s.name)
        exit(1)
    else:
        options = use_shortcut.options
        for flag in use_shortcut.flags:
            options[flag.replace('-', '_')] = True

        options_string = ''
        for k, v in sorted(iteritems(options)):
            options_string += ' --{}'.format(k.replace('_', '-'))
            if v is not True:
                options_string += ' {}'.format(v)

        output('#{{dim}}$ therapist run{}\n'.format(options_string))
        ctx.invoke(run, **options)
def use ( ctx , shortcut ) : git_dir = current_git_dir ( ) if git_dir is None : output ( NOT_GIT_REPO_MSG ) exit ( 1 ) repo_root = os . path . dirname ( git_dir ) config = get_config ( repo_root ) try : use_shortcut = config . shortcuts . get ( shortcut ) while use_shortcut . extends is not None : base = config . shortcuts . get ( use_shortcut . extends ) use_shortcut = base . extend ( use_shortcut ) except config . shortcuts . DoesNotExist as err : output ( '{}\nAvailable shortcuts:' . format ( err . message ) ) for s in config . shortcuts : output ( s . name ) exit ( 1 ) else : options = use_shortcut . options for flag in use_shortcut . flags : options [ flag . replace ( '-' , '_' ) ] = True options_string = '' for k , v in sorted ( iteritems ( options ) ) : options_string += ' --{}' . format ( k . replace ( '_' , '-' ) ) if v is not True : options_string += ' {}' . format ( v ) output ( '#{{dim}}$ therapist run{}\n' . format ( options_string ) ) ctx . invoke ( run , ** options )
Use a shortcut.