Skip to content

Commit

Permalink
Fixed an issue when printing settings and file path contains non-ASCI…
Browse files Browse the repository at this point in the history
…I chars // Resolve #2934
  • Loading branch information
ivankravets committed Aug 22, 2019
1 parent c6de3eb commit 0e56a15
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions platformio/commands/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
from platformio.compat import string_types


def format_value(raw):
if isinstance(raw, bool):
return "Yes" if raw else "No"
if isinstance(raw, string_types):
return raw
return str(raw)


@click.group(short_help="Manage PlatformIO settings")
def cli():
pass
Expand All @@ -28,25 +36,22 @@ def cli():
@click.argument("name", required=False)
def settings_get(name):
tabular_data = []
for _name, _data in sorted(app.DEFAULT_SETTINGS.items()):
if name and name != _name:
for key, options in sorted(app.DEFAULT_SETTINGS.items()):
if name and name != key:
continue
_value = app.get_setting(_name)
raw_value = app.get_setting(key)
formatted_value = format_value(raw_value)

_value_str = (str(_value)
if not isinstance(_value, string_types) else _value)
if isinstance(_value, bool):
_value_str = "Yes" if _value else "No"
if raw_value != options['value']:
default_formatted_value = format_value(options['value'])
formatted_value += "%s" % (
"\n" if len(default_formatted_value) > 10 else " ")
formatted_value += "[%s]" % click.style(default_formatted_value,
fg="yellow")

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(_value_str, fg="yellow")
_value_str += "%s[%s]" % ("\n" if len(_value_str) > 10 else " ",
_defvalue_str)
tabular_data.append(
(click.style(_name, fg="cyan"), _value_str, _data['description']))
(click.style(key,
fg="cyan"), formatted_value, options['description']))

click.echo(
tabulate(tabular_data,
Expand Down

0 comments on commit 0e56a15

Please sign in to comment.