mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-11 23:10:10 +01:00
* Two new mode `-all` and `--stdin` for check-ignore Fix #4321 Introduce new arguments --all for dvc check-ignore Add tests for dvc check-ignore --all * `--stdin` and targets only one 1. `--stdin` and targets can and only can have one 2. more tests * New tests for stdin mode and solve a problem 1. Add a new tests with mock stdin for interactive mode 2. Solve the problem of `assert "" in caplog.text` in tests always `True`. * Remove path_input interface 1. remove path_input and make _ask to a public method instead * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * Update dvc/command/check_ignore.py * fix styling Co-authored-by: karajan1001 <[email protected]> Co-authored-by: Ruslan Kuprieiev <[email protected]> Co-authored-by: Ruslan Kuprieiev <[email protected]>
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
"""Manages user prompts."""
|
|
|
|
import logging
|
|
import sys
|
|
from getpass import getpass
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def ask(prompt, limited_to=None):
|
|
if not sys.stdout.isatty():
|
|
return None
|
|
|
|
while True:
|
|
try:
|
|
answer = input(prompt + " ").lower()
|
|
except EOFError:
|
|
return None
|
|
|
|
if not limited_to:
|
|
return answer
|
|
|
|
if answer in limited_to:
|
|
return answer
|
|
|
|
logger.info(
|
|
"Your response must be one of: {options}. "
|
|
"Please try again.".format(options=limited_to)
|
|
)
|
|
|
|
|
|
def confirm(statement):
|
|
"""Ask the user for confirmation about the specified statement.
|
|
|
|
Args:
|
|
statement (unicode): statement to ask the user confirmation about.
|
|
|
|
Returns:
|
|
bool: whether or not specified statement was confirmed.
|
|
"""
|
|
prompt = f"{statement} [y/n]"
|
|
answer = ask(prompt, limited_to=["yes", "no", "y", "n"])
|
|
return answer and answer.startswith("y")
|
|
|
|
|
|
def password(statement):
|
|
"""Ask the user for a password.
|
|
|
|
Args:
|
|
statement (str): string to prompt the user with.
|
|
|
|
Returns:
|
|
str: password entered by the user.
|
|
"""
|
|
logger.info(f"{statement}: ")
|
|
return getpass("")
|