From e51680be63b114cdaf224132385623abdbde8b89 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 3 Oct 2016 17:26:24 +0300 Subject: [PATCH] Rewrite on-the-fly renamed commands --- platformio/__main__.py | 26 ++++++++++---------------- platformio/telemetry.py | 9 ++++++--- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index 05486bf0..f59db334 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys from os import getenv, listdir from os.path import join from platform import system -from sys import exit as sys_exit from traceback import format_exc import click @@ -43,22 +43,9 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 mod = __import__("platformio.commands." + name, None, None, ["cli"]) except ImportError: - try: - return self._handle_obsolate_command(name) - except AttributeError: - raise click.UsageError('No such command "%s"' % name, ctx) + raise click.UsageError('No such command "%s"' % name, ctx) return mod.cli - @staticmethod - def _handle_obsolate_command(name): - if name == "platforms": - from platformio.commands import platform - return platform.cli - elif name == "serialports": - from platformio.commands import device - return device.cli - raise AttributeError() - @click.command( cls=PlatformioCLI, @@ -103,6 +90,13 @@ def main(): except: # pylint: disable=bare-except pass + # renamed commands + if len(sys.argv) > 1: + if sys.argv[1] == "platforms": + sys.argv[1] = "platform" + if sys.argv[1] == "serialports": + sys.argv[1] = "device" + cli(None, None, None) except Exception as e: # pylint: disable=W0703 if not isinstance(e, exception.ReturnErrorCode): @@ -134,4 +128,4 @@ An unexpected error occurred. Further steps: if __name__ == "__main__": - sys_exit(main()) + sys.exit(main()) diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 121dac1b..0a8c28f2 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -110,10 +110,13 @@ class MeasurementProtocol(TelemetryBase): args = [str(s).lower() for s in ctx_args if not str(s).startswith("-")] if not args: return - if args[0] in ("lib", "platform", "serialports", "settings"): + cmd_path = args[:1] + if args[0] in ("lib", "platform", "device", "settings", + "remote"): cmd_path = args[:2] - else: - cmd_path = args[:1] + if args[0] == "remote": + if len(args) > 2 and args[1] in ("agent", "device"): + cmd_path = args[:3] self['screen_name'] = " ".join([p.title() for p in cmd_path]) def send(self, hittype):