From 476de84dc5729b263e82543de742e2a1219f6d71 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Apr 2015 12:54:59 +0100 Subject: [PATCH] Allow to specify environment prefix when initialise project // Resolve #182 --- HISTORY.rst | 2 ++ docs/userguide/cmd_init.rst | 8 ++++++++ platformio/commands/init.py | 15 +++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 33713b31..b765373a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,6 +16,8 @@ Release History (`issue #167 `_) * Allowed to choose which library to update (`issue #168 `_) +* Allowed to specify `platformio init --env-prefix `__ when initialise/update project + (`issue #182 `_) * Disabled automatic updates by default for platforms, packages and libraries (`issue #171 `_) * Fixed bug with creating copies of source files diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 4890adf1..637cdafd 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -54,6 +54,14 @@ If you initialise project with the specified ``--board``, then *PlatformIO* will create environment with enabled firmware auto-uploading. This option allows you to disable firmware auto-uploading by default. +.. option:: + --env-prefix + +An environment prefix which will be used with pair in board type. The default +value is ``autogen_``. For example, the default environment name for +``teensy_31`` board will be ``[env:autogen_teensy_31]``. + + Examples -------- diff --git a/platformio/commands/init.py b/platformio/commands/init.py index cd301978..a77d753a 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -29,7 +29,8 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 @click.option("--board", "-b", multiple=True, metavar="TYPE", callback=validate_boards) @click.option("--disable-auto-uploading", is_flag=True) -def cli(project_dir, board, disable_auto_uploading): +@click.option("--env-prefix", default="autogen_") +def cli(project_dir, board, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): @@ -78,7 +79,8 @@ def cli(project_dir, board, disable_auto_uploading): project_file) if board: - fill_project_envs(project_file, board, disable_auto_uploading) + fill_project_envs( + project_file, board, disable_auto_uploading, env_prefix) click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" @@ -92,7 +94,8 @@ def cli(project_dir, board, disable_auto_uploading): ) -def fill_project_envs(project_file, board_types, disable_auto_uploading): +def fill_project_envs(project_file, board_types, disable_auto_uploading, + env_prefix): builtin_boards = get_boards() content = [] used_envs = [] @@ -103,7 +106,7 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading): for type_ in board_types: data = builtin_boards[type_] - env_name = "[env:autogen_%s]" % type_ + env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue @@ -121,5 +124,9 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading): content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) + if not content: + return + with open(project_file, "a") as f: + content.append("") f.write("\n".join(content))