From a6f143d1ca06f27d6286648b41fb61abeab2789d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 15 Jul 2020 14:20:29 +0300 Subject: [PATCH] Dump data intended for IDE extensions/plugins using a new `platformio project idedata` command --- HISTORY.rst | 3 ++- docs | 2 +- platformio/commands/project.py | 48 ++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index cea8fb1b..8885bb03 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -24,10 +24,11 @@ PlatformIO Core 4 - Launch command with custom options declared in `"platformio.ini" `__ - Python callback as a target (use the power of Python interpreter and PlatformIO Build API) -* Display system-wide information using `platformio system info `__ command (`issue #3521 `_) +* Display system-wide information using a new `platformio system info `__ command (`issue #3521 `_) * List available project targets (including dev-platform specific and custom targets) with a new `platformio run --list-targets `__ command (`issue #3544 `_) * Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`platformio ci `__, `src_filter `__, `check_patterns `__, `library.json > srcFilter `__). Python 3.5+ is required. * Added a new ``-e, --environment`` option to `platformio project init `__ command that helps to update a PlatformIO project using existing environment +* Dump data intended for IDE extensions/plugins using a new `platformio project idedata `__ command * Do not generate ".travis.yml" for a new project, let the user have a choice * Fixed an issue with PIO Unit Testing when running multiple environments (`issue #3523 `_) * Fixed an issue with improper processing of source files added via multiple Build Middlewares (`issue #3531 `_) diff --git a/docs b/docs index 8ea98724..0da1c281 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 8ea98724069b8783575836e6ac2ee1d8a8414791 +Subproject commit 0da1c2810b62f69179cf797f0af6762d0eb9e8f9 diff --git a/platformio/commands/project.py b/platformio/commands/project.py index 27e33455..c261a9d9 100644 --- a/platformio/commands/project.py +++ b/platformio/commands/project.py @@ -14,6 +14,7 @@ # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,line-too-long +import json import os import click @@ -25,7 +26,7 @@ from platformio.ide.projectgenerator import ProjectGenerator from platformio.managers.platform import PlatformManager from platformio.project.config import ProjectConfig from platformio.project.exception import NotPlatformIOProjectError -from platformio.project.helpers import is_platformio_project +from platformio.project.helpers import is_platformio_project, load_project_ide_data @click.group(short_help="Project Manager") @@ -38,9 +39,7 @@ def cli(): "-d", "--project-dir", default=os.getcwd, - type=click.Path( - exists=True, file_okay=True, dir_okay=True, writable=True, resolve_path=True - ), + type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), ) @click.option("--json-output", is_flag=True) def project_config(project_dir, json_output): @@ -54,7 +53,6 @@ def project_config(project_dir, json_output): "Computed project configuration for %s" % click.style(project_dir, fg="cyan") ) for section, options in config.as_tuple(): - click.echo() click.secho(section, fg="cyan") click.echo("-" * len(section)) click.echo( @@ -66,6 +64,46 @@ def project_config(project_dir, json_output): tablefmt="plain", ) ) + click.echo() + return None + + +@cli.command("idedata", short_help="Dump data intended for IDE extensions/plugins") +@click.option( + "-d", + "--project-dir", + default=os.getcwd, + type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True), +) +@click.option("-e", "--environment", multiple=True) +@click.option("--json-output", is_flag=True) +def project_idedata(project_dir, environment, json_output): + if not is_platformio_project(project_dir): + raise NotPlatformIOProjectError(project_dir) + with fs.cd(project_dir): + config = ProjectConfig.get_instance() + config.validate(environment) + environment = list(environment or config.envs()) + + if json_output: + return click.echo(json.dumps(load_project_ide_data(project_dir, environment))) + + for envname in environment: + click.echo("Environment: " + click.style(envname, fg="cyan", bold=True)) + click.echo("=" * (13 + len(envname))) + click.echo( + tabulate( + [ + (click.style(name, bold=True), "=", json.dumps(value, indent=2)) + for name, value in load_project_ide_data( + project_dir, envname + ).items() + ], + tablefmt="plain", + ) + ) + click.echo() + return None