Skip to content

Commit

Permalink
Allow to specify environment prefix when initialise project // Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Apr 23, 2015
1 parent 0d64807 commit 476de84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/userguide/cmd_init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
15 changes: 11 additions & 4 deletions platformio/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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"
Expand All @@ -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 = []
Expand All @@ -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
Expand All @@ -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))

0 comments on commit 476de84

Please sign in to comment.