forked from platformio/platformio-core
Validate passed boards before project initialization
This commit is contained in:
@ -11,13 +11,25 @@ from platformio import app, exception
|
||||
from platformio.util import get_boards, get_source_dir
|
||||
|
||||
|
||||
def validate_boards(ctx, param, value):
|
||||
unknown_boards = set(value) - set(get_boards().keys())
|
||||
try:
|
||||
assert not unknown_boards
|
||||
return value
|
||||
except AssertionError:
|
||||
raise click.BadParameter(
|
||||
"%s. Please search for the board types using "
|
||||
"`platformio boards` command" % ", ".join(unknown_boards))
|
||||
|
||||
|
||||
@click.command("init", short_help="Initialize new PlatformIO based project")
|
||||
@click.option("--project-dir", "-d", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option("--board", "-b", multiple=True, metavar="TYPE")
|
||||
@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):
|
||||
def cli(project_dir, board, disable_auto_uploading, ide):
|
||||
|
||||
project_file = join(project_dir, "platformio.ini")
|
||||
src_dir = join(project_dir, "src")
|
||||
@ -33,11 +45,12 @@ def cli(project_dir, board, disable_auto_uploading):
|
||||
# ask about auto-uploading
|
||||
if board and app.get_setting("enable_prompts"):
|
||||
disable_auto_uploading = not click.confirm(
|
||||
"\nWould you like to enable firmware auto-uploading when project "
|
||||
"Would you like to enable firmware auto-uploading when project "
|
||||
"is successfully built using `platformio run` command? \n"
|
||||
"Don't forget that you can upload firmware manually using "
|
||||
"`platformio run --target upload` command."
|
||||
)
|
||||
click.echo("")
|
||||
|
||||
if project_dir == getcwd():
|
||||
click.secho("\nThe current working directory", fg="yellow", nl=False)
|
||||
@ -45,9 +58,10 @@ def cli(project_dir, board, disable_auto_uploading):
|
||||
click.secho(
|
||||
"will be used for the new project.\n"
|
||||
"You can specify another project directory via\n"
|
||||
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n",
|
||||
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
|
||||
fg="yellow"
|
||||
)
|
||||
click.echo("")
|
||||
|
||||
click.echo("The next files/directories will be created in %s" %
|
||||
click.style(project_dir, fg="cyan"))
|
||||
@ -70,7 +84,7 @@ def cli(project_dir, board, disable_auto_uploading):
|
||||
if board:
|
||||
fill_project_envs(project_file, board, disable_auto_uploading)
|
||||
click.secho(
|
||||
"Project has been successfully initialized!\nUseful commands:\n"
|
||||
"\nProject has been successfully initialized!\nUseful commands:\n"
|
||||
"`platformio run` - process/build project from the current "
|
||||
"directory\n"
|
||||
"`platformio run --target upload` or `platformio run -t upload` "
|
||||
|
Reference in New Issue
Block a user