Implement "platformio settings" command

This commit is contained in:
Ivan Kravets
2014-11-29 22:58:10 +02:00
parent d8837e4756
commit 22297b9cfd
4 changed files with 184 additions and 0 deletions

View File

@ -4,6 +4,7 @@ Release History
0.9.0 (?)
---------
* Implemented `platformio settings <http://docs.platformio.ikravets.com/en/latest/userguide/cmd_settings.html>`_ command
* Added *Migration Manager* which simplifies process with upgrading to a
major release
* Added *Telemetry Service* which should help us make *PlatformIO* better

View File

@ -0,0 +1,114 @@
.. _cmd_settings:
platformio settings
===================
Manage PlatformIO settings
.. contents::
platformio settings get
-----------------------
Usage
~~~~~
.. code-block:: bash
platformio settings get [NAME]
Description
~~~~~~~~~~~
Get/List existing settings
Examples
~~~~~~~~
1. List all settings and current their values
.. code-block:: bash
$ platformio settings get
Name Value [Default] Description
------------------------------------------------------------------------------------------
auto_update_libraries Yes Automatically update libraries (Yes/No)
auto_update_platforms Yes Automatically update platforms (Yes/No)
check_libraries_interval 7 Check for the library updates interval (days)
check_platformio_interval 3 Check for the new PlatformIO interval (days)
check_platforms_interval 7 Check for the platforms updates interval (days)
2. Show specified setting
.. code-block:: bash
$ platformio settings get auto_update_platforms
Name Value [Default] Description
------------------------------------------------------------------------------------------
auto_update_platforms Yes Automatically update platforms (Yes/No)
platformio settings set
-----------------------
Usage
~~~~~
.. code-block:: bash
platformio settings set NAME VALUE
Description
~~~~~~~~~~~
Set new value for the setting
Examples
~~~~~~~~
Change to check for the new PlatformIO each day
.. code-block:: bash
$ platformio settings set check_platformio_interval 1
The new value for the setting has been set!
Name Value [Default] Description
------------------------------------------------------------------------------------------
check_platformio_interval 1 [3] Check for the new PlatformIO interval (days)
platformio settings reset
-------------------------
Usage
~~~~~
.. code-block:: bash
platformio settings reset
Description
~~~~~~~~~~~
Reset settings to default
Examples
~~~~~~~~
.. code-block:: bash
$ platformio settings reset
The settings have been reseted!
Name Value [Default] Description
------------------------------------------------------------------------------------------
auto_update_libraries Yes Automatically update libraries (Yes/No)
auto_update_platforms Yes Automatically update platforms (Yes/No)
check_libraries_interval 7 Check for the library updates interval (days)
check_platformio_interval 3 Check for the new PlatformIO interval (days)
check_platforms_interval 7 Check for the platform updates interval (days)

View File

@ -21,6 +21,7 @@ To print all available commands and options use:
cmd_run
cmd_search
cmd_serialports
cmd_settings
cmd_show
cmd_uninstall
cmd_update

View File

@ -0,0 +1,68 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
import click
from platformio import app
@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):
list_tpl = "{name:<40} {value:<35} {description}"
click.echo(list_tpl.format(
name=click.style("Name", fg="cyan"),
value=(click.style("Value", fg="green") +
click.style(" [Default]", fg="yellow")),
description="Description"
))
click.echo("-" * 90)
for _name, _data in sorted(app.DEFAULT_SETTINGS.items()):
if name and name != _name:
continue
_value = app.get_setting(_name)
_value_str = str(_value)
if isinstance(_value, bool):
_value_str = "Yes" if _value else "No"
_value_str = click.style(_value_str, fg="green")
if _value != _data['value']:
_defvalue_str = str(_data['value'])
if isinstance(_data['value'], bool):
_defvalue_str = "Yes" if _data['value'] else "No"
_value_str += click.style(" [%s]" % _defvalue_str, fg="yellow")
else:
_value_str += click.style(" ", fg="yellow")
click.echo(list_tpl.format(
name=click.style(_name, fg="cyan"),
value=_value_str,
description=_data['description']
))
@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)