2017-06-05 16:02:39 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2014-11-29 22:58:10 +02:00
|
|
|
|
|
|
|
import click
|
2019-08-17 20:55:16 +03:00
|
|
|
from tabulate import tabulate
|
2014-11-29 22:58:10 +02:00
|
|
|
|
|
|
|
from platformio import app
|
2019-07-08 17:21:28 +03:00
|
|
|
from platformio.compat import string_types
|
2014-11-29 22:58:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@click.group(short_help="Manage PlatformIO settings")
|
|
|
|
def cli():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command("get", short_help="Get existing setting/-s")
|
|
|
|
@click.argument("name", required=False)
|
|
|
|
def settings_get(name):
|
2019-08-17 20:55:16 +03:00
|
|
|
tabular_data = []
|
2014-11-29 22:58:10 +02:00
|
|
|
for _name, _data in sorted(app.DEFAULT_SETTINGS.items()):
|
|
|
|
if name and name != _name:
|
|
|
|
continue
|
|
|
|
_value = app.get_setting(_name)
|
|
|
|
|
2019-07-08 17:21:28 +03:00
|
|
|
_value_str = (str(_value)
|
|
|
|
if not isinstance(_value, string_types) else _value)
|
2014-11-29 22:58:10 +02:00
|
|
|
if isinstance(_value, bool):
|
|
|
|
_value_str = "Yes" if _value else "No"
|
|
|
|
|
|
|
|
if _value != _data['value']:
|
|
|
|
_defvalue_str = str(_data['value'])
|
|
|
|
if isinstance(_data['value'], bool):
|
|
|
|
_defvalue_str = "Yes" if _data['value'] else "No"
|
2019-08-17 20:55:16 +03:00
|
|
|
_value_str += " [%s]" % _defvalue_str
|
|
|
|
_value_str = click.style(_value_str, fg="yellow")
|
|
|
|
|
|
|
|
tabular_data.append((_name, _value_str, _data['description']))
|
2014-11-29 22:58:10 +02:00
|
|
|
|
2019-08-17 20:55:16 +03:00
|
|
|
click.echo(
|
|
|
|
tabulate(tabular_data,
|
|
|
|
headers=["Name", "Current value [Default]", "Description"]))
|
2014-11-29 22:58:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command("set", short_help="Set new value for the setting")
|
|
|
|
@click.argument("name")
|
|
|
|
@click.argument("value")
|
|
|
|
@click.pass_context
|
|
|
|
def settings_set(ctx, name, value):
|
|
|
|
app.set_setting(name, value)
|
|
|
|
click.secho("The new value for the setting has been set!", fg="green")
|
|
|
|
ctx.invoke(settings_get, name=name)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command("reset", short_help="Reset settings to default")
|
|
|
|
@click.pass_context
|
|
|
|
def settings_reset(ctx):
|
|
|
|
app.reset_settings()
|
|
|
|
click.secho("The settings have been reseted!", fg="green")
|
|
|
|
ctx.invoke(settings_get)
|