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


Python click.prompt方法代碼示例

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


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

示例1: run

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def run(host, port, username, version, timeout, password, logfile, filename, ssl, read_only):
  if version:
    print("cycli {}".format(__version__))
    sys.exit(0)

  if username and not password:
    password = click.prompt("Password", hide_input=True, show_default=False, type=str)

  try:
    cycli = Cycli(host, port, username, password, logfile, filename, ssl, read_only, timeout)
  except AuthError:
    print("Unauthorized. See cycli --help for authorization instructions.")
  except ConnectionError:
    print("Connection refused. Is Neo4j turned on?")
  else:
    cycli.run() 
開發者ID:nicolewhite,項目名稱:cycli,代碼行數:18,代碼來源:main.py

示例2: getcloudloginkey

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def getcloudloginkey(ctx, account):
    """ Return keys for cloudlogin
    """
    from bitsharesbase.account import PasswordKey

    password = click.prompt("Passphrase", hide_input=True).strip()
    t = [["role", "wif", "pubkey", "accounts"]]
    for role in ["owner", "active", "memo"]:
        wif = PasswordKey(account, password, role=role)
        pubkey = format(wif.get_public_key(), ctx.bitshares.rpc.chain_params["prefix"])

        t.append(
            [
                role,
                str(wif.get_private_key()),
                pubkey,
                ctx.bitshares.wallet.getAccountFromPublicKey(pubkey) or "",
            ]
        )

    print_table(t) 
開發者ID:bitshares,項目名稱:uptick,代碼行數:23,代碼來源:tools.py

示例3: allow

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def allow(ctx, foreign_account, permission, weight, threshold, account):
    """ Add a key/account to an account's permission
    """
    if not foreign_account:
        from bitsharesbase.account import PasswordKey

        pwd = click.prompt(
            "Password for Key Derivation", hide_input=True, confirmation_prompt=True
        )
        foreign_account = format(
            PasswordKey(account, pwd, permission).get_public(), "BTS"
        )
    print_tx(
        ctx.bitshares.allow(
            foreign_account,
            weight=weight,
            account=account,
            permission=permission,
            threshold=threshold,
        )
    ) 
開發者ID:bitshares,項目名稱:uptick,代碼行數:23,代碼來源:account.py

示例4: get_field

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def get_field(schema, path, options, type=str, default=None, msg=None):

    field = path[-1]
    field = field.replace("_", " ")
    field = re.sub(r"(?<=\w)([A-Z])", r" \1", field)
    field = field.capitalize()

    if msg is None:
        msg = "Enter {}".format(field)

    data = ""
    while True:
        if not default:
            data = click.prompt(msg, type=type)

        else:
            data = click.prompt(msg, default=default)

        if not validate_field(schema, path, options, data):
            click.echo("data incorrect. Enter again")

        else:
            break

    return data 
開發者ID:nutanix,項目名稱:calm-dsl,代碼行數:27,代碼來源:main.py

示例5: get_custom_vm_image

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def get_custom_vm_image(azure_obj, account_id, location):
    custom_image_id = ""
    custom_images = azure_obj.custom_images(account_id, location)
    custom_image_names = list(custom_images.keys())

    if not custom_image_names:
        click.echo("\n{}".format(highlight_text("No custom image present")))

    else:
        click.echo("\nChoose from given custom images")
        for ind, name in enumerate(custom_image_names):
            click.echo("\t {}. {}".format(str(ind + 1), highlight_text(name)))

        while True:
            res = click.prompt("\nEnter the index of custom image", default=1)
            if (res > len(custom_image_names)) or (res <= 0):
                click.echo("Invalid index !!! ")

            else:
                custom_image = custom_image_names[res - 1]
                custom_image_id = custom_images[custom_image]
                click.echo("{} selected".format(highlight_text(custom_image)))
                break

    return {"source_image_id": custom_image_id, "use_custom_image": True} 
開發者ID:nutanix,項目名稱:calm-dsl,代碼行數:27,代碼來源:main.py

示例6: get_private_ip_info

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def get_private_ip_info():

    allocation_method = ""
    ip_address = ""

    allocation_methods = azure.ALLOCATION_METHODS
    click.echo("\nChoose from given ip allocation method")
    for ind, name in enumerate(allocation_methods):
        click.echo("\t {}. {}".format(str(ind + 1), highlight_text(name)))

    while True:
        res = click.prompt("\nEnter the index of allocation methods", default=1)
        if (res > len(allocation_methods)) or (res <= 0):
            click.echo("Invalid index !!! ")

        else:
            allocation_method = allocation_methods[res - 1]
            click.echo("{} selected".format(highlight_text(allocation_method)))
            break

    if allocation_method == "Static":
        ip_address = click.prompt("\nEnter IP Address", default="")

    return {"ip_allocation_method": allocation_method, "ip_address": ip_address} 
開發者ID:nutanix,項目名稱:calm-dsl,代碼行數:26,代碼來源:main.py

示例7: ask_for_configs

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def ask_for_configs():
    remote_path = click.prompt("Remote path", default="~/remote/path")
    ssh_host = click.prompt("SSH host", default="ssh_host")
    ssh_user = click.prompt("SSH username or enter '-' to skip",
                            default="ssh_user")
    ignores = click.prompt("Files or folders to ignore "
                           "(separated by space)", default=" ")

    if ssh_user == "-":
        ssh_user = None

    if ignores.strip():
        ignores = ignores.split(" ")
    else:
        ignores = []

    return psync.generate_config(ssh_user=ssh_user,
                                 ssh_host=ssh_host,
                                 remote_path=remote_path,
                                 ignores=ignores) 
開發者ID:lazywei,項目名稱:psync,代碼行數:22,代碼來源:cli.py

示例8: get_input_key

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def get_input_key():
    """Input API key and validate"""
    click.secho("No API key found!", fg="yellow", bold=True)
    click.secho("Please visit {} and get an API token.".format(RequestHandler.BASE_URL),
                fg="yellow",
                bold=True)
    while True:
        confkey = click.prompt(click.style("Enter API key",
                                           fg="yellow", bold=True))
        if len(confkey) == 32:  # 32 chars
            try:
                int(confkey, 16)  # hexadecimal
            except ValueError:
                click.secho("Invalid API key", fg="red", bold=True)
            else:
                break
        else:
            click.secho("Invalid API key", fg="red", bold=True)
    return confkey 
開發者ID:architv,項目名稱:soccer-cli,代碼行數:21,代碼來源:main.py

示例9: manual_login_success

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def manual_login_success(token, username, password):
    if token:
        # Login using authentication token
        floyd_logger.info(
            "Please paste the authentication token from %s/settings/security.",
            floyd.floyd_web_host)
        access_token = click.prompt('This is an invisible field. Paste token and press ENTER', type=str, hide_input=True)
        access_token = access_token.strip()

        if not access_token:
            floyd_logger.info("Empty token received. Make sure your shell is handling the token appropriately.")
            floyd_logger.info("See docs for help: http://docs.floydhub.com/faqs/authentication/")
            return

    elif username or password:
        access_token = get_access_code_from_password(username, password)
    else:
        return False

    user = AuthClient().get_user(access_token)
    AuthConfigManager.set_access_token(
        AccessToken(username=user.username,
                    token=access_token))
    floyd_logger.info("Login Successful as %s", user.username)
    return True 
開發者ID:floydhub,項目名稱:floyd-cli,代碼行數:27,代碼來源:auth.py

示例10: ask_for_import

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def ask_for_import(project: Project) -> None:
    """Show possible importable files and ask user to decide"""
    importable_files = list(find_importable_files(project))
    if not importable_files:
        return
    stream.echo(
        stream.cyan("Found following files from other formats that you may import:")
    )
    for i, (key, filepath) in enumerate(importable_files):
        stream.echo(f"{i}. {stream.green(filepath.as_posix())} ({key})")
    stream.echo(
        "{}. {}".format(
            len(importable_files),
            stream.yellow("don't do anything, I will import later."),
        )
    )
    choice = click.prompt(
        "Please select:",
        type=click.Choice([str(i) for i in range(len(importable_files) + 1)]),
        show_default=False,
    )
    if int(choice) == len(importable_files):
        return
    key, filepath = importable_files[int(choice)]
    do_import(project, filepath, key) 
開發者ID:frostming,項目名稱:pdm,代碼行數:27,代碼來源:actions.py

示例11: prompt_login

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def prompt_login(ctx, param, provider):
    system = ctx.params.get('system','production')
    if provider == 'auger':
        username = ctx.params.get('username')
        if not username:
            username = click.prompt('username', default=None)

        organization = ctx.params.get('organization')
        if not organization:
            organization = click.prompt('organization', default=None)

        password = ctx.params.get('password')
        if not password:
            password = click.prompt('password', default=None, confirmation_prompt=False, hide_input=True)

        return {'username':username, 'organization':organization, 'password':password, 'system':system, 'name':provider}
    return {'username':None, 'organization':None, 'password':None, 'system':system, 'name':provider} 
開發者ID:augerai,項目名稱:a2ml,代碼行數:19,代碼來源:cmd_auth.py

示例12: set_cluster_hostname

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def set_cluster_hostname(oo_cfg):
    first_master = next((host for host in oo_cfg.deployment.hosts if host.is_master()), None)
    message = """
You have chosen to install a single master cluster (non-HA).

In a single master cluster, the cluster host name (Ansible variable openshift_master_cluster_public_hostname) is set by default to the host name of the single master. In a multiple master (HA) cluster, the FQDN of a host must be provided that will be configured as a proxy. This could be either an existing load balancer configured to balance all masters on
port 8443 or a new host that would have HAProxy installed on it.

(Optional)
If you want to override the cluster host name now to something other than the default (the host name of the single master), or if you think you might add masters later to become an HA cluster and want to future proof your cluster host name choice, please provide a FQDN. Otherwise, press ENTER to continue and accept the default.
"""
    click.echo(message)
    cluster_hostname = click.prompt('Enter hostname or IP address',
                                    default=str(first_master))
    oo_cfg.deployment.variables['openshift_master_cluster_hostname'] = cluster_hostname
    oo_cfg.deployment.variables['openshift_master_cluster_public_hostname'] = cluster_hostname 
開發者ID:openshift,項目名稱:origin-ci-tool,代碼行數:18,代碼來源:cli_installer.py

示例13: _helper

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def _helper(self):
      # use "default=''" so that the "leave blank to skip" works (instead of click re-prompting until it gets a value)
      import click
      res_prompt = click.prompt('Email to which to share the results (type "skip" to not send email)', type=str, default=self.last_email_val)

      # check if blank
      res_prompt = res_prompt.strip()
      if res_prompt=='skip':
        ping_matomo("/cost/share_email?original=F&provided=F")
        return None

      # quick validate
      # shortest email is: a@b.c
      # Longest email is: shadishadishadishadi@shadishadishadishadi.shadi
      if len(res_prompt) >= 5:
        if len(res_prompt) <= 50:
          if bool(self.EMAIL_REGEX.match(res_prompt)):
            ping_matomo("/cost/share_email?original=F&provided=T")
            return [res_prompt]

      # otherwise, invalid email
      logger.error("Invalid email address: '%s'"%res_prompt)
      raise ValueError 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:25,代碼來源:utils.py

示例14: prompt

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def prompt(self, emailTo):
    if emailTo is not None:
      if len(emailTo) > 0:
        # user already requested email
        ping_matomo("/cost/share_email?original=T")
        return emailTo

    # get last used email if available
    self.last_email_val = self.last_email_cl.get()
    if self.last_email_val is None: self.last_email_val='skip'

    # prompt for email
    while True:
      try:
        res = self._helper()
        return res
      except ValueError:
        pass 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:20,代碼來源:utils.py

示例15: test_oneInputNoLast

# 需要導入模塊: import click [as 別名]
# 或者: from click import prompt [as 別名]
def test_oneInputNoLast(self, ping_matomo):
    """
    # build a fake click command so that the click.prompt will be emulated
    # https://click.palletsprojects.com/en/7.x/testing/?highlight=test#input-streams
    """
    import click
    @click.command()
    def cmd():
      from isitfit.utils import PromptToEmailIfNotRequested
      pte = PromptToEmailIfNotRequested()
      import tempfile
      with tempfile.NamedTemporaryFile() as fh:
        pte.last_email_cl.fn = fh.name # overwrite file to save last-used email
        pte.prompt(None)

    # trigger
    from click.testing import CliRunner
    runner = CliRunner()
    result = runner.invoke(cmd, input='me@example.com\n')
    print(result.__dict__) # in case of exception, this will show details
    assert not result.exception
    assert '[skip]' in result.output 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:24,代碼來源:test_utils.py


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