Allow to specify environment prefix when initialise project // Resolve #182

This commit is contained in:
Ivan Kravets
2015-04-23 12:54:59 +01:00
parent 0d648074e4
commit 476de84dc5
3 changed files with 21 additions and 4 deletions

View File

@ -16,6 +16,8 @@ Release History
(`issue #167 <https://github.com/platformio/platformio/issues/167>`_) (`issue #167 <https://github.com/platformio/platformio/issues/167>`_)
* Allowed to choose which library to update * Allowed to choose which library to update
(`issue #168 <https://github.com/platformio/platformio/issues/168>`_) (`issue #168 <https://github.com/platformio/platformio/issues/168>`_)
* Allowed to specify `platformio init --env-prefix <http://docs.platformio.org/en/latest/userguide/cmd_init.html#cmdoption--env-prefix>`__ when initialise/update project
(`issue #182 <https://github.com/platformio/platformio/issues/182>`_)
* Disabled automatic updates by default for platforms, packages and libraries * Disabled automatic updates by default for platforms, packages and libraries
(`issue #171 <https://github.com/platformio/platformio/issues/171>`_) (`issue #171 <https://github.com/platformio/platformio/issues/171>`_)
* Fixed bug with creating copies of source files * Fixed bug with creating copies of source files

View File

@ -54,6 +54,14 @@ If you initialise project with the specified ``--board``, then *PlatformIO*
will create environment with enabled firmware auto-uploading. This option will create environment with enabled firmware auto-uploading. This option
allows you to disable firmware auto-uploading by default. 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 Examples
-------- --------

View File

@ -29,7 +29,8 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
@click.option("--board", "-b", multiple=True, metavar="TYPE", @click.option("--board", "-b", multiple=True, metavar="TYPE",
callback=validate_boards) callback=validate_boards)
@click.option("--disable-auto-uploading", is_flag=True) @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 # ask about auto-uploading
if board and app.get_setting("enable_prompts"): if board and app.get_setting("enable_prompts"):
@ -78,7 +79,8 @@ def cli(project_dir, board, disable_auto_uploading):
project_file) project_file)
if board: if board:
fill_project_envs(project_file, board, disable_auto_uploading) fill_project_envs(
project_file, board, disable_auto_uploading, env_prefix)
click.secho( click.secho(
"\nProject has been successfully initialized!\nUseful commands:\n" "\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() builtin_boards = get_boards()
content = [] content = []
used_envs = [] used_envs = []
@ -103,7 +106,7 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading):
for type_ in board_types: for type_ in board_types:
data = builtin_boards[type_] data = builtin_boards[type_]
env_name = "[env:autogen_%s]" % type_ env_name = "[env:%s%s]" % (env_prefix, type_)
if env_name in used_envs: if env_name in used_envs:
continue continue
@ -121,5 +124,9 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading):
content.append("%stargets = upload" % ("# " if disable_auto_uploading content.append("%stargets = upload" % ("# " if disable_auto_uploading
else "")) else ""))
if not content:
return
with open(project_file, "a") as f: with open(project_file, "a") as f:
content.append("")
f.write("\n".join(content)) f.write("\n".join(content))