當前位置: 首頁>>代碼示例>>Python>>正文


Python click.group方法代碼示例

本文整理匯總了Python中click.group方法的典型用法代碼示例。如果您正苦於以下問題:Python click.group方法的具體用法?Python click.group怎麽用?Python click.group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在click的用法示例。


在下文中一共展示了click.group方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: list_groups

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def list_groups(ctx):
    """
    (deprecated) List user groups.

    Please use `pdtools cloud list-groups`.
    """
    url = ctx.obj['pdserver_url'] + "/api/groups"
    result = pdserver_request('GET', url)
    groups = result.json()

    for group in groups:
        print("{} {}".format(group['_id'], group['name']))

        print("  Users:")
        for user_id in group['users']:
            print("    {}".format(user_id))

        print("  Routers:")
        for router_id in group['routers']:
            print("    {}".format(router_id)) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:22,代碼來源:groups.py

示例2: test_completion

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def test_completion():
    @click.group()
    def foo_group():
        pass

    @foo_group.command()
    def foo_cmd():
        pass

    @click.group()
    def foobar_group():
        pass

    @foobar_group.command()
    def foobar_cmd():
        pass

    c = ClickCompleter(click.CommandCollection(sources=[foo_group, foobar_group]))
    completions = list(c.get_completions(Document(u"foo")))

    assert set(x.text for x in completions) == set([u"foo_cmd", u"foobar_cmd"]) 
開發者ID:click-contrib,項目名稱:click-repl,代碼行數:23,代碼來源:test_command_collection.py

示例3: test_completion

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def test_completion():
    @click.group()
    def root_command():
        pass

    @root_command.group()
    def first_level_command():
        pass

    @first_level_command.command()
    def second_level_command_one():
        pass

    @first_level_command.command()
    def second_level_command_two():
        pass

    c = ClickCompleter(root_command)
    completions = list(c.get_completions(Document(u"first_level_command ")))

    assert set(x.text for x in completions) == set(
        [u"second_level_command_one", u"second_level_command_two"]
    ) 
開發者ID:click-contrib,項目名稱:click-repl,代碼行數:25,代碼來源:test_basic.py

示例4: _detect_wifi_ssid

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def _detect_wifi_ssid():
    system = _system()
    if system not in SUPPORTED_SYSTEMS:
        return False, 'Unknown operation system {0}'.format(system)

    if system == 'Darwin':
        command = ['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '-I']
        pattern = re.compile(r' SSID: (?P<ssid>.+)')
    elif system == 'Linux':
        command = ['nmcli', '-t', '-f', 'active,ssid', 'dev', 'wifi']
        pattern = re.compile(r"yes:'(?P<ssid>.+)'")
    else:
        command = ['netsh', 'wlan', 'show', 'interfaces']
        pattern = re.compile(r' SSID.+: (?P<ssid>.+)\r')

    rs = _exec(command)
    match = re.search(pattern, rs)
    if not match:
        return False, rs

    return True, match.group('ssid') 
開發者ID:cls1991,項目名稱:ng,代碼行數:23,代碼來源:ng.py

示例5: invoke

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def invoke(resource, action, api_key, **kwargs):
    """Attempt to invoke the provided action on each resource.

        Arguments:
            resource: Object defining a Sfx resource (chart, dashboard, dashboard group, etc)
            action: String to create, update, read, or delete a resource
            api_key: String

        Returns:
            The response from the action taken.
    """
    res = resource.with_api_token(api_key)
    try:
        action_fn = getattr(res, action)
    except AttributeError:
        msg = "Attempted to execute unsupported action '{0}' on resource '{1}'."
        click.echo(msg.format(action, resource.__get__('name')))
        exit()

    return action_fn(**kwargs) 
開發者ID:Nike-Inc,項目名稱:signal_analog,代碼行數:22,代碼來源:cli.py

示例6: parse_data

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def parse_data(stats_dir):
    def parse_file(file):
        experiment = None
        base_file = path.basename(file)
        m = SUMMARY_REGEX.match(base_file)
        if m:
            experiment = 'all features'
        m = ANSWER_REGEX.match(base_file)
        if m:
            experiment = m.group(1)
        if experiment is None:
            raise ValueError('Incorrect file name argument: {}'.format(base_file))
        with open(file) as f:
            data = json.load(f)
            return seq(data.items()).map(lambda kv: {
                'experiment': experiment,
                'result': kv[0].replace('Answer.', ''),
                'score': kv[1]
            })

    rows = seq(glob(path.join(stats_dir, 'test*.json')))\
        .sorted().flat_map(parse_file).to_pandas()
    return rows 
開發者ID:Pinafore,項目名稱:qb,代碼行數:25,代碼來源:performance.py

示例7: test_ClickOption_failsWithPrompt

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def test_ClickOption_failsWithPrompt(runner):
  @click.group()
  def isitfit(): pass

  @click.group()
  @click.option('--prompt', default='foo', prompt='my prompt', type=str)
  def cost(prompt): pass

  @click.command()
  def analyze(): pass

  cost.add_command(analyze)
  isitfit.add_command(cost)

  # invoke and assert
  result = runner.invoke(isitfit, ['cost', '--help'])
  assert False # the invoke above is expected to halt at the prompt and fail, but not working as expected ATM 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:19,代碼來源:test_clickDescendents.py

示例8: test_IsitfitOption_worksWithPrompt

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def test_IsitfitOption_worksWithPrompt(runner):
  """
  This test is the working counter-part of test_ClickOption_failsWithPrompt which was expected to fail
  """
  from isitfit.cli.click_descendents import isitfit_option_base

  @click.group()
  def isitfit(): pass

  # Note that in the below, callback is not set
  @click.group()
  @isitfit_option_base('--prompt', default='foo', prompt='my prompt', type=str)
  def cost(prompt): pass

  @click.command()
  def analyze(): pass

  cost.add_command(analyze)
  isitfit.add_command(cost)

  # invoke and assert
  result = runner.invoke(isitfit, ['cost', '--help'])
  assert not result.exception 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:25,代碼來源:test_clickDescendents.py

示例9: test_IsitfitOptionProfile_ok

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def test_IsitfitOptionProfile_ok(runner):
  from isitfit.cli.click_descendents import isitfit_option_profile

  @click.group()
  def isitfit(): pass

  @click.group()
  @isitfit_option_profile()
  def cost(prompt): pass

  @click.command()
  def analyze(): pass

  cost.add_command(analyze)
  isitfit.add_command(cost)

  # invoke and assert
  result = runner.invoke(isitfit, ['cost', '--help'])
  assert not result.exception 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:21,代碼來源:test_clickDescendents.py

示例10: check_links

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def check_links(script_path: str) -> None:
    with open(script_path, "r") as f:
        contents = f.read()
    link_matches = list(MARKDOWN_URL_REGEX.finditer(contents))
    for link_match in link_matches:
        url = link_match.group(0).rstrip(")").lstrip("(")
        req = urllib.request.Request(url, headers={"User-Agent": "Magic Browser"})
        logging.info(f"Checking link [{url}]")
        try:
            urllib.request.urlopen(req, timeout=5)
        except urllib.error.HTTPError as e:
            raise ValueError(f"Bad link [{url}] found in {script_path}: {e}")
        except Exception as e:
            logging.warning(
                f"SKIPPING: Could not access [{url}] found in {script_path}: {e}"
            ) 
開發者ID:snorkel-team,項目名稱:snorkel-tutorials,代碼行數:18,代碼來源:build.py

示例11: cmd_share

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def cmd_share(filename, role, type, email, domain, discoverable):
    if type in ['user', 'group'] and email is None:
        print('--email is required for user or group type.')
        sys.exit(1)
    elif type == 'domain' and domain is None:
        print('--domain is required for domain type.')
        sys.exit(1)
    config_dir = _get_current_config_dir()
    id = get_id_by_path(filename)
    cmd = '{exe} --config {config} share'.format(
        exe=DRIVE_EXE, config=config_dir)
    if role:
        cmd += ' --role {role}'.format(role=role)
    if type:
        cmd += ' --type {type}'.format(type=type)
    if email:
        cmd += ' --email {email}'.format(email=email)
    if domain:
        cmd += ' --domain {domain}'.format(domain=domain)
    if discoverable:
        cmd += ' --discoverable'
    # if revoke:
    #     cmd += ' --revoke'
    cmd += ' {id}'.format(id=id)
    subprocess.call(cmd, shell=True) 
開發者ID:wkentaro,項目名稱:gshell,代碼行數:27,代碼來源:__init__.py

示例12: group_grant

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def group_grant(ctx, userid, groupid):
    """Add a user into a group (grant privilege)

    \b
    Parameters:
        <userid> - username, AoR or SIP URI for subscriber
        <groupid> - group name
    """
    udata = parse_user_spec(ctx, userid)
    ctx.vlog(
        "Adding user [%s@%s] in group [%s]",
        udata["username"],
        udata["domain"],
        groupid,
    )
    e = create_engine(ctx.gconfig.get("db", "rwurl"))
    e.execute(
        "insert into grp (username, domain, grp) values (%s, %s, %s)",
        udata["username"],
        udata["domain"],
        groupid,
    ) 
開發者ID:kamailio,項目名稱:kamcli,代碼行數:24,代碼來源:cmd_group.py

示例13: address_list

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def address_list(ctx, mode, group):
    """Show details for address records in memory

    \b
    Parameters:
        <group> - address group
    """
    if mode == "all":
        command_ctl(ctx, "permissions.addressDump", [])
        command_ctl(ctx, "permissions.subnetDump", [])
        command_ctl(ctx, "permissions.domainDump", [])
    elif mode == "addresses":
        command_ctl(ctx, "permissions.addressDump", [])
    elif mode == "subnets":
        command_ctl(ctx, "permissions.subnetDump", [])
    elif mode == "domains":
        command_ctl(ctx, "permissions.domainDump", [])
    else:
        command_ctl(ctx, "permissions.addressDump", []) 
開發者ID:kamailio,項目名稱:kamcli,代碼行數:21,代碼來源:cmd_address.py

示例14: error

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def error():
    """
    Get or share information about an error

    If you'd like to dig into an error more yourself,
    you can get the last few lines of context about it
    from `cci error info`.

    If you'd like to submit it to a developer for conversation,
    you can use the `cci error gist` command. Just make sure
    that your GitHub access token has the 'create gist' scope.

    For more information on working with errors in CumulusCI visit:
    https://cumulusci.readthedocs.io/en/latest/features.html#working-with-errors
    """


# Commands for group: project 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:20,代碼來源:cci.py

示例15: service_info

# 需要導入模塊: import click [as 別名]
# 或者: from click import group [as 別名]
def service_info(runtime, service_name, plain):
    try:
        plain = plain or runtime.global_config.cli__plain_output
        service_config = runtime.keychain.get_service(service_name)
        service_data = [["Key", "Value"]]
        service_data.extend(
            [
                [click.style(k, bold=True), str(v)]
                for k, v in service_config.config.items()
            ]
        )
        wrap_cols = ["Value"] if not plain else None
        service_table = CliTable(service_data, title=service_name, wrap_cols=wrap_cols)
        service_table._table.inner_heading_row_border = False
        service_table.echo(plain)
    except ServiceNotConfigured:
        click.echo(
            "{0} is not configured for this project.  Use service connect {0} to configure.".format(
                service_name
            )
        )


# Commands for group: org 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:26,代碼來源:cci.py


注:本文中的click.group方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。