forked from platformio/platformio-core
Add global -f, --force option which will force to accept any confirmation prompts // Resolve #152
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
VERSION = (1, 4, 0)
|
VERSION = (2, 0, "0.dev0")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
@ -37,14 +37,16 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904
|
|||||||
|
|
||||||
@click.command(cls=PlatformioCLI)
|
@click.command(cls=PlatformioCLI)
|
||||||
@click.version_option(__version__, prog_name="PlatformIO")
|
@click.version_option(__version__, prog_name="PlatformIO")
|
||||||
|
@click.option("--force", "-f", is_flag=True,
|
||||||
|
help="Force to accept any confirmation prompts")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx):
|
def cli(ctx, force):
|
||||||
maintenance.on_platformio_start(ctx)
|
maintenance.on_platformio_start(ctx, force)
|
||||||
|
|
||||||
|
|
||||||
@cli.resultcallback()
|
@cli.resultcallback()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def process_result(ctx, result):
|
def process_result(ctx, result, force): # pylint: disable=W0613
|
||||||
maintenance.on_platformio_end(ctx, result)
|
maintenance.on_platformio_end(ctx, result)
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ def main():
|
|||||||
# /en/latest/security.html#insecureplatformwarning
|
# /en/latest/security.html#insecureplatformwarning
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
cli(None)
|
cli(None, None)
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
if not isinstance(e, exception.ReturnErrorCode):
|
if not isinstance(e, exception.ReturnErrorCode):
|
||||||
maintenance.on_platformio_exception(e)
|
maintenance.on_platformio_exception(e)
|
||||||
|
@ -47,6 +47,11 @@ DEFAULT_SETTINGS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SESSION_VARS = {
|
||||||
|
"force_option": False
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class State(object):
|
class State(object):
|
||||||
|
|
||||||
def __init__(self, path=None):
|
def __init__(self, path=None):
|
||||||
@ -101,9 +106,12 @@ def set_state_item(name, value):
|
|||||||
|
|
||||||
|
|
||||||
def get_setting(name):
|
def get_setting(name):
|
||||||
# disable prompts for Continuous Integration systems
|
if name == "enable_prompts":
|
||||||
if name == "enable_prompts" and getenv("CI", "").lower() == "true":
|
# disable prompts for Continuous Integration systems
|
||||||
return False
|
# 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()
|
_env_name = "PLATFORMIO_SETTING_%s" % name.upper()
|
||||||
if _env_name in environ:
|
if _env_name in environ:
|
||||||
@ -127,3 +135,12 @@ def reset_settings():
|
|||||||
with State() as data:
|
with State() as data:
|
||||||
if "settings" in data:
|
if "settings" in data:
|
||||||
del data['settings']
|
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
|
||||||
|
@ -20,7 +20,8 @@ from platformio.platforms.base import PlatformFactory
|
|||||||
from platformio.util import get_home_dir, get_lib_dir
|
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)
|
telemetry.on_command(ctx)
|
||||||
after_upgrade(ctx)
|
after_upgrade(ctx)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user