diff --git a/docs b/docs index 5e906bbc..1f171d4b 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 5e906bbc756d605abb2cedca52a1afef67220479 +Subproject commit 1f171d4bfdb5ee4d0746be72b381b57746a4e860 diff --git a/platformio/commands/project.py b/platformio/commands/project.py index 9c9f76cb..534bb72b 100644 --- a/platformio/commands/project.py +++ b/platformio/commands/project.py @@ -15,16 +15,16 @@ import click from platformio.project.commands.config import project_config_cmd -from platformio.project.commands.data import project_data_cmd from platformio.project.commands.init import project_init_cmd +from platformio.project.commands.metadata import project_metadata_cmd @click.group( "project", commands=[ project_config_cmd, - project_data_cmd, project_init_cmd, + project_metadata_cmd, ], short_help="Project Manager", ) diff --git a/platformio/package/commands/install.py b/platformio/package/commands/install.py index 9bbe9505..472d0ae8 100644 --- a/platformio/package/commands/install.py +++ b/platformio/package/commands/install.py @@ -99,12 +99,12 @@ def install_project_dependencies(options): for env in config.envs(): if environments and env not in environments: continue - if not options["silent"]: + if not options.get("silent"): click.echo( "Resolving %s environment packages..." % click.style(env, fg="cyan") ) already_up_to_date = not install_project_env_dependencies(env, options) - if not options["silent"] and already_up_to_date: + if not options.get("silent") and already_up_to_date: click.secho("Already up-to-date.", fg="green") diff --git a/platformio/project/commands/data.py b/platformio/project/commands/data.py deleted file mode 100644 index 303bfd7f..00000000 --- a/platformio/project/commands/data.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2014-present PlatformIO -# -# 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. - -import json -import os - -import click -from tabulate import tabulate - -from platformio import fs -from platformio.project.config import ProjectConfig -from platformio.project.exception import NotPlatformIOProjectError -from platformio.project.helpers import is_platformio_project, load_build_metadata - - -@click.command("data", 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_data_cmd(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_build_metadata(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_build_metadata(project_dir, envname).items() - ], - tablefmt="plain", - ) - ) - click.echo() - - return None diff --git a/platformio/project/commands/metadata.py b/platformio/project/commands/metadata.py new file mode 100644 index 00000000..06457574 --- /dev/null +++ b/platformio/project/commands/metadata.py @@ -0,0 +1,80 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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. + +import json +import os + +import click +from tabulate import tabulate + +from platformio import fs +from platformio.package.commands.install import install_project_dependencies +from platformio.project.config import ProjectConfig +from platformio.project.helpers import load_build_metadata + + +@click.command( + "metadata", short_help="Dump metadata 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", "environments", multiple=True) +@click.option("--json-output", is_flag=True) +@click.option("--json-output-path", type=click.Path(resolve_path=True)) +def project_metadata_cmd(project_dir, environments, json_output, json_output_path): + with fs.cd(project_dir): + config = ProjectConfig.get_instance() + config.validate(environments) + environments = list(environments or config.envs()) + build_metadata = load_build_metadata(project_dir, environments) + + if not json_output: + install_project_dependencies( + options=dict( + project_dir=project_dir, + environments=environments, + ) + ) + click.echo() + + if json_output or json_output_path: + if json_output_path: + if os.path.isdir(json_output_path): + json_output_path = os.path.join(json_output_path, "metadata.json") + with open(json_output_path, mode="w", encoding="utf8") as fp: + json.dump(build_metadata, fp) + click.secho(f"Saved metadata to the {json_output_path}", fg="green") + if json_output: + click.echo(json.dumps(build_metadata)) + return + + for envname, metadata in build_metadata.items(): + 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 metadata.items() + ], + tablefmt="plain", + ) + ) + click.echo() + + return