Make scripts available via CLI (#2426)
* Rename sqlalchemy migrate script * Add script support to CLI
This commit is contained in:
1 parent
a2e45b8fdd
commit
3447fdc76f
4 files changed
+105
-79
No files matched your search
@@ -0,0 +1,22 @@
|
||||
"""Home Assistant command line scripts."""
|
||||
import importlib
|
||||
import os
|
||||
|
||||
|
||||
def run(args):
|
||||
"""Run a script."""
|
||||
scripts = [fil[:-3] for fil in os.listdir(os.path.dirname(__file__))
|
||||
if fil.endswith('.py') and fil != '__init__.py']
|
||||
|
||||
if not args:
|
||||
print('Please specify a script to run.')
|
||||
print('Available scripts:', ', '.join(scripts))
|
||||
return 1
|
||||
|
||||
if args[0] not in scripts:
|
||||
print('Invalid script specified.')
|
||||
print('Available scripts:', ', '.join(scripts))
|
||||
return 1
|
||||
|
||||
script = importlib.import_module('homeassistant.scripts.' + args[0])
|
||||
return script.run(args[1:])
|
||||
Reference in new issue
Block a user