Show valid environment names when user typed unknown values

This commit is contained in:
Ivan Kravets
2015-10-03 15:38:33 +01:00
parent ec844961c7
commit 1426e78793
3 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
VERSION = (2, 3, 3)
VERSION = (2, 3, "4.dev0")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -36,9 +36,12 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
if not config.sections():
raise exception.ProjectEnvsNotAvailable()
unknown = set(environment) - set([s[4:] for s in config.sections()])
known = set([s[4:] for s in config.sections()
if s.startswith("env:")])
unknown = set(environment) - known
if unknown:
raise exception.UnknownEnvNames(", ".join(unknown))
raise exception.UnknownEnvNames(
", ".join(unknown), ", ".join(known))
# clean obsolete .pioenvs dir
if not disable_auto_clean:

View File

@ -104,17 +104,17 @@ class UnsupportedArchiveType(PlatformioException):
class ProjectEnvsNotAvailable(PlatformioException):
MESSAGE = "Please setup environments in `platformio.ini` file."
MESSAGE = "Please setup environments in `platformio.ini` file"
class InvalidEnvName(PlatformioException):
MESSAGE = "Invalid environment '%s'. The name must start " "with 'env:'."
MESSAGE = "Invalid environment '%s'. The name must start with 'env:'"
class UnknownEnvNames(PlatformioException):
MESSAGE = "Unknown environment names '%s'."
MESSAGE = "Unknown environment names '%s'. Valid names are '%s'"
class GetSerialPortsError(PlatformioException):