Skip to content

Commit

Permalink
List available project targets with a new "platformio run –list-targe…
Browse files Browse the repository at this point in the history
…ts" command // Resolve #3544
  • Loading branch information
ivankravets committed Jun 22, 2020
1 parent f19491f commit 9f05519
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PlatformIO Core 4
- Python callback as a target (use the power of Python interpreter and PlatformIO Build API)


* List available project targets (including dev-platform specific and custom targets) with a new `platformio run --list-targets <https://docs.platformio.org/page/core/userguide/cmd_run.html#cmdoption-platformio-run-list-targets>`__ command (`issue #3544 <https://github.com/platformio/platformio-core/issues/3544>`_)
* Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`platformio ci <https://docs.platformio.org/page/core/userguide/cmd_ci.html>`__, `src_filter <https://docs.platformio.org/page/projectconf/section_env_build.html#src-filter>`__, `check_patterns <https://docs.platformio.org/page/projectconf/section_env_check.html#check-patterns>`__, `library.json > srcFilter <https://docs.platformio.org/page/librarymanager/config.html#srcfilter>`__). Python 3.5+ is required.
* Added a new ``-e, --environment`` option to `platformio project init <https://docs.platformio.org/page/core/userguide/project/cmd_init.html#cmdoption-platformio-project-init-e>`__ command that helps to update a PlatformIO project using existing environment
* Fixed an issue with PIO Unit Testing when running multiple environments (`issue #3523 <https://github.com/platformio/platformio-core/issues/3523>`_)
Expand Down
45 changes: 40 additions & 5 deletions platformio/commands/run/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import operator
import os
from multiprocessing import cpu_count
from os import getcwd
from os.path import isfile
from time import time

import click
Expand All @@ -26,7 +26,7 @@
from platformio.commands.run.processor import EnvironmentProcessor
from platformio.commands.test.processor import CTX_META_TEST_IS_RUNNING
from platformio.project.config import ProjectConfig
from platformio.project.helpers import find_project_dir_above
from platformio.project.helpers import find_project_dir_above, load_project_ide_data

# pylint: disable=too-many-arguments,too-many-locals,too-many-branches

Expand All @@ -43,7 +43,7 @@
@click.option(
"-d",
"--project-dir",
default=getcwd,
default=os.getcwd,
type=click.Path(
exists=True, file_okay=True, dir_okay=True, writable=True, resolve_path=True
),
Expand All @@ -68,6 +68,7 @@
@click.option("-s", "--silent", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.option("--disable-auto-clean", is_flag=True)
@click.option("--list-targets", is_flag=True)
@click.pass_context
def cli(
ctx,
Expand All @@ -80,11 +81,12 @@ def cli(
silent,
verbose,
disable_auto_clean,
list_targets,
):
app.set_session_var("custom_project_conf", project_conf)

# find project directory on upper level
if isfile(project_dir):
if os.path.isfile(project_dir):
project_dir = find_project_dir_above(project_dir)

is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta
Expand All @@ -93,6 +95,9 @@ def cli(
config = ProjectConfig.get_instance(project_conf)
config.validate(environment)

if list_targets:
return print_target_list(list(environment) or config.envs())

# clean obsolete build dir
if not disable_auto_clean:
build_dir = config.get_optional_dir("build")
Expand Down Expand Up @@ -261,3 +266,33 @@ def print_processing_summary(results):
is_error=failed_nums,
fg="red" if failed_nums else "green",
)


def print_target_list(envs):
tabular_data = []
for env, data in load_project_ide_data(os.getcwd(), envs).items():
tabular_data.extend(
sorted(
[
(
click.style(env, fg="cyan"),
t["group"],
click.style(t.get("name"), fg="yellow"),
t["title"],
t.get("description"),
)
for t in data.get("targets", [])
],
key=operator.itemgetter(1, 2),
)
)
tabular_data.append((None, None, None, None, None))
click.echo(
tabulate(
tabular_data,
headers=[
click.style(s, bold=True)
for s in ("Environment", "Group", "Name", "Title", "Description")
],
),
)

0 comments on commit 9f05519

Please sign in to comment.