diff --git a/HISTORY.rst b/HISTORY.rst index 29fd1083..91973810 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,7 +15,8 @@ Release History `#55 `_) * Added ``--json-output`` option to `platformio boards `__ - command which allows to return the output in `JSON `_ format + and `platformio search `__ + commands which allow to return the output in `JSON `_ format (`issue #42 `_) * Allowed to ignore some libs from *Library Dependency Finder* via `ignore_libs `_ option diff --git a/docs/userguide/cmd_search.rst b/docs/userguide/cmd_search.rst index a411c2e7..3a60b25f 100644 --- a/docs/userguide/cmd_search.rst +++ b/docs/userguide/cmd_search.rst @@ -10,11 +10,7 @@ Usage .. code-block:: bash - # Print all available development platforms - platformio search - - # Filter platforms by "Query" - platformio search QUERY + platformio search QUERY [OPTIONS] Description @@ -22,11 +18,33 @@ Description Search for development :ref:`Platforms ` +Options +~~~~~~~ + +.. option:: + --json-output + +Return the output in `JSON `_ format + Examples -------- -1. Search for TI development platforms +1. Print all available development platforms + +.. code-block:: bash + + $ platformio search + atmelavr - An embedded platform for Atmel AVR microcontrollers (with Arduino Framework) + atmelsam - An embedded platform for Atmel SAM microcontrollers (with Arduino Framework) + digistump - An embedded platform for Digistump boards (with Arduino Framework) + stm32 - An embedded platform for STMicroelectronics ARM microcontrollers + teensy - An embedded platform for Teensy boards (with Arduino Framework) + timsp430 - An embedded platform for TI MSP430 microcontrollers (with Energia Framework) + titiva - An embedded platform for TI TIVA C ARM microcontrollers (with Energia and OpenCM3 Frameworks) + ... + +2. Search for TI development platforms .. code-block:: bash @@ -34,9 +52,12 @@ Examples timsp430 - An embedded platform for TI MSP430 microcontrollers (with Energia Framework) titiva - An embedded platform for TI TIVA C ARM microcontrollers (with Energia Framework) -2. Search for development platforms which support "Arduino Framework" +3. Search for development platforms which support "Arduino Framework" .. code-block:: bash $ platformio search arduino - atmelavr - An embedded platform for Atmel AVR microcontrollers (with Arduino Framework) + atmelavr - An embedded platform for Atmel AVR microcontrollers (with Arduino Framework) + atmelsam - An embedded platform for Atmel SAM microcontrollers (with Arduino Framework) + digistump - An embedded platform for Digistump boards (with Arduino Framework) + teensy - An embedded platform for Teensy boards (with Arduino Framework) diff --git a/platformio/commands/search.py b/platformio/commands/search.py index 80a2d80d..3af2aa5b 100644 --- a/platformio/commands/search.py +++ b/platformio/commands/search.py @@ -1,6 +1,8 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. +import json + import click from platformio.platforms.base import PlatformFactory @@ -8,18 +10,32 @@ from platformio.platforms.base import PlatformFactory @click.command("search", short_help="Search for development platforms") @click.argument("query", required=False) -def cli(query): - for platform in PlatformFactory.get_platforms().keys(): +@click.option("--json-output", is_flag=True) +def cli(query, json_output): + + data = [] + platforms = PlatformFactory.get_platforms().keys() + platforms.sort() + for platform in platforms: p = PlatformFactory.newPlatform(platform) name = p.get_name() - shinfo = p.get_short_info() + info = p.get_short_info() if query == "all": query = "" - search_data = "%s %s" % (name, shinfo) + search_data = "%s %s" % (name, info) if query and query.lower() not in search_data.lower(): continue - click.echo("{name:<20} - {info}".format( - name=click.style(name, fg="cyan"), info=shinfo)) + data.append({ + "name": name, + "info": info + }) + + if json_output: + click.echo(json.dumps(data)) + else: + for item in data: + click.echo("{name:<20} - {info}".format( + name=click.style(item['name'], fg="cyan"), info=item['info']))