forked from platformio/platformio-core
Allow to specify environment prefix when initialise project // Resolve #182
This commit is contained in:
@ -16,6 +16,8 @@ Release History
|
||||
(`issue #167 <https://github.com/platformio/platformio/issues/167>`_)
|
||||
* Allowed to choose which library to update
|
||||
(`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
|
||||
(`issue #171 <https://github.com/platformio/platformio/issues/171>`_)
|
||||
* Fixed bug with creating copies of source files
|
||||
|
@ -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
|
||||
--------
|
||||
|
||||
|
@ -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))
|
||||
|
Reference in New Issue
Block a user