From 6894d2c5d2d10efc3efaf1a8baf1a3f8c0189c83 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 27 Aug 2016 20:32:21 +0300 Subject: [PATCH] Allow to pass project file path to run command instead project dir --- platformio/commands/run.py | 9 ++++++++- platformio/util.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 825d09ac..0f8c7402 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -38,7 +38,7 @@ from platformio.managers.platform import PlatformFactory default=getcwd, type=click.Path( exists=True, - file_okay=False, + file_okay=True, dir_okay=True, writable=True, resolve_path=True)) @@ -54,6 +54,13 @@ def cli(ctx, # pylint: disable=R0913,R0914 silent, verbose, disable_auto_clean): + # find project directory on upper level + if isfile(project_dir): + project_dir = util.find_project_dir_above(project_dir) + + if not util.is_platformio_project(project_dir): + raise exception.NotPlatformIOProject(project_dir) + with util.cd(project_dir): # clean obsolete .pioenvs dir if not disable_auto_clean: diff --git a/platformio/util.py b/platformio/util.py index dcbf298a..4dbf530e 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -194,6 +194,16 @@ def get_project_dir(): return os.getcwd() +def find_project_dir_above(path): + if isfile(path): + path = dirname(path) + if is_platformio_project(path): + return path + if isdir(dirname(path)): + return find_project_dir_above(dirname(path)) + return None + + def is_platformio_project(project_dir=None): if not project_dir: project_dir = get_project_dir()