forked from platformio/platformio-core
Fix handler for renamed commands
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
VERSION = (3, 2, "0a1")
|
VERSION = (3, 2, "0a2")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import sys
|
|
||||||
from os import getenv, listdir
|
from os import getenv, listdir
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from platform import system
|
from platform import system
|
||||||
|
from sys import exit as sys_exit
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -43,9 +43,22 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904
|
|||||||
mod = __import__("platformio.commands." + name, None, None,
|
mod = __import__("platformio.commands." + name, None, None,
|
||||||
["cli"])
|
["cli"])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
try:
|
||||||
|
return self._handle_obsolate_command(name)
|
||||||
|
except AttributeError:
|
||||||
raise click.UsageError('No such command "%s"' % name, ctx)
|
raise click.UsageError('No such command "%s"' % name, ctx)
|
||||||
return mod.cli
|
return mod.cli
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _handle_obsolate_command(name):
|
||||||
|
if name == "platforms":
|
||||||
|
from platformio.commands import platform
|
||||||
|
return platform.cli
|
||||||
|
elif name == "serialports":
|
||||||
|
from platformio.commands import device
|
||||||
|
return device.cli
|
||||||
|
raise AttributeError()
|
||||||
|
|
||||||
|
|
||||||
@click.command(
|
@click.command(
|
||||||
cls=PlatformioCLI,
|
cls=PlatformioCLI,
|
||||||
@ -90,13 +103,6 @@ def main():
|
|||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# renamed commands
|
|
||||||
if len(sys.argv) > 1:
|
|
||||||
if sys.argv[1] == "platforms":
|
|
||||||
sys.argv[1] = "platform"
|
|
||||||
if sys.argv[1] == "serialports":
|
|
||||||
sys.argv[1] = "device"
|
|
||||||
|
|
||||||
cli(None, None, None)
|
cli(None, None, None)
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
if not isinstance(e, exception.ReturnErrorCode):
|
if not isinstance(e, exception.ReturnErrorCode):
|
||||||
@ -128,4 +134,4 @@ An unexpected error occurred. Further steps:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys_exit(main())
|
||||||
|
@ -111,7 +111,8 @@ class MeasurementProtocol(TelemetryBase):
|
|||||||
if not args:
|
if not args:
|
||||||
return
|
return
|
||||||
cmd_path = args[:1]
|
cmd_path = args[:1]
|
||||||
if args[0] in ("lib", "platform", "device", "settings", "remote"):
|
if args[0] in ("lib", "platform", "platforms", "serialports", "device",
|
||||||
|
"settings", "remote"):
|
||||||
cmd_path = args[:2]
|
cmd_path = args[:2]
|
||||||
if args[0] == "remote":
|
if args[0] == "remote":
|
||||||
if len(args) > 2 and args[1] in ("agent", "device"):
|
if len(args) > 2 and args[1] in ("agent", "device"):
|
||||||
|
Reference in New Issue
Block a user