Python click 模块,pass_obj() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用click.pass_obj()

项目:lambada    作者:Superpedestrian    | 项目源码 | 文件源码
def test_cli(self):
        """Test out the tune finder."""
        path = make_fixture_path('basic')

        @cli.cli.command()
        @click.pass_obj
        def clitest(obj):  # pylint: disable=unused-variable
            """Command to test base context."""
            self.assertEqual(obj['path'], path)
            self.assertTrue('hi' in obj['tune'].dancers)
        result = self.runner.invoke(cli.cli, ['--path', path, 'clitest'])
        self.assertEqual(0, result.exit_code)
        result = self.runner.invoke(
            cli.cli,
            ['--path', make_fixture_path('nodancers', None), 'clitest']
        )
        self.assertEqual(1, result.exit_code)
        self.assertIn(
            'Unable to find Lambada class declaration',
            result.output
        )
项目:srep    作者:Answeror    | 项目源码 | 文件源码
def packargs(func):
    import click
    return click.pass_obj(_packargs(func))
项目:cget    作者:pfultz2    | 项目源码 | 文件源码
def use_prefix(f):
    @click.option('-p', '--prefix', help='Set prefix used to install packages')
    @click.option('-v', '--verbose', is_flag=True, help="Enable verbose mode")
    @click.option('-B', '--build-path', help='Set the path for the build directory to use when building the package')
    @click.pass_obj
    @functools.wraps(f)
    def w(obj, prefix, verbose, build_path, *args, **kwargs):
        p = CGetPrefix(prefix or obj.get('PREFIX'), verbose or obj.get('VERBOSE'), build_path or obj.get('BUILD_PATH'))
        f(p, *args, **kwargs)
    return w
项目:cwmon    作者:RescueTime    | 项目源码 | 文件源码
def __repr__(self):
        return "Options: %s".format(self.__dict__)


#: You're going to want to read the docs for `Complex Applications`_
#: to understand ``@click.pass_context`` and ``@click.pass_obj`` and
#: how/why we're using them to propagate options from the top-level
#: command (the one tagged with ``@click.group()``) down to subcommands
#: (the ones tagged with ``@cwmon.command()``).
#:
#: .. _Complex Applications: http://click.pocoo.org/6/complex/
项目:ipbb    作者:ipbus    | 项目源码 | 文件源码
def ls( env ):
    '''Lists all available project areas
    '''
    lProjects = _getprojects(env)
    print ( 'Main work area:', env.workPath )
    print ( 'Projects areas:', ', '.join( [
        lProject + ('*' if lProject == env.project else '') for lProject in lProjects
    ] ) )
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# @proj.command()
# @click.argument( 'projname' )
# @click.pass_obj
# def printpath( env, projname ):

#     lProjects = _getprojects(env)

#     if projname not in lProjects:
#         raise click.ClickException('Requested work area not found. Available areas: %s' % ', '.join(lProjects))

#     print ( os.path.join( env.proj, projname ))
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------