We are introducing a new subcommand for managing your clusters. Configuring your CLI to talk to your cluster is a single command now `dcos cluster setup`. Moreover, the CLI can now be aware of multiple clusters with cluster specific configuration managed by the CLI. Subcommands will be installed for the current "attached" cluster only. To install a subcommand for all your configured clusters, use `--global`. Note that `DCOS_CONFIG` environment variable will not take effect in "cluster" mode since we are now managing different clusters in the CLI.
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
import sys
|
|
|
|
from functools import wraps
|
|
|
|
import docopt
|
|
|
|
from dcos import emitting
|
|
|
|
emitter = emitting.FlatEmitter()
|
|
|
|
|
|
def decorate_docopt_usage(func):
|
|
"""Handle DocoptExit exception
|
|
|
|
:param func: function
|
|
:type func: function
|
|
:return: wrapped function
|
|
:rtype: function
|
|
"""
|
|
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
try:
|
|
result = func(*args, **kwargs)
|
|
except docopt.DocoptExit as e:
|
|
emitter.publish("Command not recognized\n")
|
|
emitter.publish(e)
|
|
return 1
|
|
return result
|
|
return wrapper
|
|
|
|
|
|
def confirm(prompt, yes):
|
|
"""
|
|
:param prompt: message to display to the terminal
|
|
:type prompt: str
|
|
:param yes: whether to assume that the user responded with yes
|
|
:type yes: bool
|
|
:returns: True if the user responded with yes; False otherwise
|
|
:rtype: bool
|
|
"""
|
|
|
|
if yes:
|
|
return True
|
|
else:
|
|
while True:
|
|
sys.stdout.write('{} [yes/no] '.format(prompt))
|
|
sys.stdout.flush()
|
|
response = sys.stdin.readline().strip().lower()
|
|
if response == 'yes' or response == 'y':
|
|
return True
|
|
elif response == 'no' or response == 'n':
|
|
return False
|
|
else:
|
|
msg = "'{}' is not a valid response.".format(response)
|
|
emitter.publish(msg)
|