in azdev/operations/setup.py [0:0]
def _interactive_setup():
from knack.prompting import prompt_y_n, prompt
while True:
cli_path = None
ext_repos = []
exts = []
# CLI Installation
if prompt_y_n('Do you plan to develop CLI modules?'):
display("\nGreat! Please enter the path to your azure-cli repo, 'EDGE' to install "
"the latest developer edge build or simply press "
"RETURN and we will attempt to find your repo for you.")
while True:
cli_path = prompt('\nPath (RETURN to auto-find): ', None)
cli_path = os.path.abspath(os.path.expanduser(cli_path)) if cli_path else None
CLI_SENTINEL = 'azure-cli.pyproj'
if not cli_path:
cli_path = find_file(CLI_SENTINEL)
if not cli_path:
raise CLIError('Unable to locate your CLI repo. Things to check:'
'\n Ensure you have cloned the repo. '
'\n Specify the path explicitly with `-c PATH`. '
'\n If you run with `-c` to autodetect, ensure you are running '
'this command from a folder upstream of the repo.')
try:
if cli_path != 'EDGE':
cli_path = _check_path(cli_path, CLI_SENTINEL)
display('Found: {}'.format(cli_path))
break
except CLIError as ex:
logger.error(ex)
continue
else:
display('\nOK. We will install the latest `azure-cli` from PyPI then.')
def add_ext_repo(path):
try:
_check_repo(path)
except CLIError as ex:
logger.error(ex)
return False
ext_repos.append(path)
display('Repo {} OK.'.format(path))
return True
# Determine extension repos
# Allows the user to simply press RETURN to use their cwd, assuming they are in their desired extension
# repo directory. To use multiple extension repos or identify a repo outside the cwd, they must specify
# the path.
if prompt_y_n('\nDo you plan to develop CLI extensions?'):
display('\nGreat! Input the paths for the extension repos you wish to develop for, one per '
'line. You can add as many repos as you like. (TIP: to quickly get started, press RETURN to '
'use your current working directory).')
first_repo = True
while True:
msg = '\nPath ({}): '.format('RETURN to use current directory' if first_repo else 'RETURN to continue')
ext_repo_path = prompt(msg, None)
if not ext_repo_path:
if first_repo and not add_ext_repo(os.getcwd()):
first_repo = False
continue
break
add_ext_repo(os.path.abspath(os.path.expanduser(ext_repo_path)))
first_repo = False
display('\nTIP: you can manage extension repos later with the `azdev extension repo` commands.')
# Determine extensions
if ext_repos:
if prompt_y_n('\nWould you like to install certain extensions by default? '):
display('\nGreat! Input the names of the extensions you wish to install, one per '
'line. You can add as many repos as you like. Use * to install all extensions. '
'Press RETURN to continue to the next step.')
available_extensions = [x['name'] for x in list_extensions()]
while True:
ext_name = prompt('\nName (RETURN to continue): ', None)
if not ext_name:
break
if ext_name == '*':
exts = [x['path'] for x in list_extensions()]
break
if ext_name not in available_extensions:
logger.error("Extension '%s' not found. Check the spelling, and make "
"sure you added the repo first!", ext_name)
continue
display('Extension {} OK.'.format(ext_name))
exts.append(next(x['path'] for x in list_extensions() if x['name'] == ext_name))
display('\nTIP: you can manage extensions later with the `azdev extension` commands.')
subheading('Summary')
display('CLI: {}'.format(cli_path if cli_path else 'PyPI'))
display('Extension repos: {}'.format(' '.join(ext_repos)))
display('Extensions: \n {}'.format('\n '.join(exts)))
if prompt_y_n('\nProceed with installation? '):
return cli_path, ext_repos, exts
raise CLIError('Installation aborted.')