本文整理汇总了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()
示例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)
示例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,
)
)
示例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
示例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}
示例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}
示例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)
示例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
示例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
示例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)
示例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}
示例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
示例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
示例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
示例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