Add global -f, --force option which will force to accept any confirmation prompts // Resolve #152

This commit is contained in:
Ivan Kravets
2015-04-16 17:04:45 +01:00
parent 0234fcd2e3
commit 8d75194884
4 changed files with 29 additions and 9 deletions

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
VERSION = (1, 4, 0)
VERSION = (2, 0, "0.dev0")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -37,14 +37,16 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904
@click.command(cls=PlatformioCLI)
@click.version_option(__version__, prog_name="PlatformIO")
@click.option("--force", "-f", is_flag=True,
help="Force to accept any confirmation prompts")
@click.pass_context
def cli(ctx):
maintenance.on_platformio_start(ctx)
def cli(ctx, force):
maintenance.on_platformio_start(ctx, force)
@cli.resultcallback()
@click.pass_context
def process_result(ctx, result):
def process_result(ctx, result, force): # pylint: disable=W0613
maintenance.on_platformio_end(ctx, result)
@ -54,7 +56,7 @@ def main():
# /en/latest/security.html#insecureplatformwarning
requests.packages.urllib3.disable_warnings()
cli(None)
cli(None, None)
except Exception as e: # pylint: disable=W0703
if not isinstance(e, exception.ReturnErrorCode):
maintenance.on_platformio_exception(e)

View File

@ -47,6 +47,11 @@ DEFAULT_SETTINGS = {
}
SESSION_VARS = {
"force_option": False
}
class State(object):
def __init__(self, path=None):
@ -101,9 +106,12 @@ def set_state_item(name, value):
def get_setting(name):
# disable prompts for Continuous Integration systems
if name == "enable_prompts" and getenv("CI", "").lower() == "true":
return False
if name == "enable_prompts":
# disable prompts for Continuous Integration systems
# and when global "--force" option is set
if any([getenv("CI", "").lower() == "true",
get_session_var("force_option")]):
return False
_env_name = "PLATFORMIO_SETTING_%s" % name.upper()
if _env_name in environ:
@ -127,3 +135,12 @@ def reset_settings():
with State() as data:
if "settings" in data:
del data['settings']
def get_session_var(name, default=None):
return SESSION_VARS.get(name, default)
def set_session_var(name, value):
assert name in SESSION_VARS
SESSION_VARS[name] = value

View File

@ -20,7 +20,8 @@ from platformio.platforms.base import PlatformFactory
from platformio.util import get_home_dir, get_lib_dir
def on_platformio_start(ctx):
def on_platformio_start(ctx, force):
app.set_session_var("force_option", force)
telemetry.on_command(ctx)
after_upgrade(ctx)