reflex.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. """Reflex CLI to create, run, and deploy apps."""
  2. from __future__ import annotations
  3. import atexit
  4. from importlib.util import find_spec
  5. from pathlib import Path
  6. from typing import TYPE_CHECKING
  7. import click
  8. from reflex_cli.v2.deployments import hosting_cli
  9. from reflex import constants
  10. from reflex.config import get_config
  11. from reflex.constants.base import LITERAL_ENV
  12. from reflex.custom_components.custom_components import custom_components_cli
  13. from reflex.environment import environment
  14. from reflex.state import reset_disk_state_manager
  15. from reflex.utils import console, redir, telemetry
  16. from reflex.utils.exec import should_use_granian
  17. def set_loglevel(ctx: click.Context, self: click.Parameter, value: str | None):
  18. """Set the log level.
  19. Args:
  20. ctx: The click context.
  21. self: The click command.
  22. value: The log level to set.
  23. """
  24. if value is not None:
  25. loglevel = constants.LogLevel.from_string(value)
  26. console.set_log_level(loglevel)
  27. @click.group
  28. @click.version_option(constants.Reflex.VERSION, message="%(version)s")
  29. def cli():
  30. """Reflex CLI to create, run, and deploy apps."""
  31. loglevel_option = click.option(
  32. "--loglevel",
  33. type=click.Choice(
  34. [loglevel.value for loglevel in constants.LogLevel],
  35. case_sensitive=False,
  36. ),
  37. is_eager=True,
  38. callback=set_loglevel,
  39. expose_value=False,
  40. help="The log level to use.",
  41. )
  42. def _init(
  43. name: str,
  44. template: str | None = None,
  45. ai: bool = False,
  46. ):
  47. """Initialize a new Reflex app in the given directory."""
  48. from reflex.utils import exec, prerequisites
  49. # Show system info
  50. exec.output_system_info()
  51. if ai:
  52. redir.reflex_build_redirect()
  53. return
  54. # Validate the app name.
  55. app_name = prerequisites.validate_app_name(name)
  56. console.rule(f"[bold]Initializing {app_name}")
  57. # Check prerequisites.
  58. prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)
  59. prerequisites.initialize_reflex_user_directory()
  60. prerequisites.ensure_reflex_installation_id()
  61. # Set up the web project.
  62. prerequisites.initialize_frontend_dependencies()
  63. # Initialize the app.
  64. template = prerequisites.initialize_app(app_name, template)
  65. # Initialize the .gitignore.
  66. prerequisites.initialize_gitignore()
  67. # Initialize the requirements.txt.
  68. needs_user_manual_update = prerequisites.initialize_requirements_txt()
  69. template_msg = f" using the {template} template" if template else ""
  70. # Finish initializing the app.
  71. console.success(
  72. f"Initialized {app_name}{template_msg}."
  73. + (
  74. f" Make sure to add {constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION} to your requirements.txt or pyproject.toml file."
  75. if needs_user_manual_update
  76. else ""
  77. )
  78. )
  79. @cli.command()
  80. @loglevel_option
  81. @click.option(
  82. "--name",
  83. metavar="APP_NAME",
  84. help="The name of the app to initialize.",
  85. )
  86. @click.option(
  87. "--template",
  88. help="The template to initialize the app with.",
  89. )
  90. @click.option(
  91. "--ai",
  92. is_flag=True,
  93. help="Use AI to create the initial template. Cannot be used with existing app or `--template` option.",
  94. )
  95. def init(
  96. name: str,
  97. template: str | None,
  98. ai: bool,
  99. ):
  100. """Initialize a new Reflex app in the current directory."""
  101. _init(name, template, ai)
  102. def _run(
  103. env: constants.Env = constants.Env.DEV,
  104. frontend: bool = True,
  105. backend: bool = True,
  106. frontend_port: int | None = None,
  107. backend_port: int | None = None,
  108. backend_host: str | None = None,
  109. ):
  110. """Run the app in the given directory."""
  111. from reflex.utils import build, exec, prerequisites, processes
  112. config = get_config()
  113. backend_host = backend_host or config.backend_host
  114. # Set env mode in the environment
  115. environment.REFLEX_ENV_MODE.set(env)
  116. # Show system info
  117. exec.output_system_info()
  118. # If no --frontend-only and no --backend-only, then turn on frontend and backend both
  119. frontend, backend = prerequisites.check_running_mode(frontend, backend)
  120. if not frontend and backend:
  121. _skip_compile()
  122. prerequisites.assert_in_reflex_dir()
  123. # Check that the app is initialized.
  124. if frontend and prerequisites.needs_reinit():
  125. _init(name=config.app_name)
  126. # Delete the states folder if it exists.
  127. reset_disk_state_manager()
  128. # Find the next available open port if applicable.
  129. if frontend:
  130. auto_increment_frontend = not bool(frontend_port or config.frontend_port)
  131. frontend_port = processes.handle_port(
  132. "frontend",
  133. (
  134. frontend_port
  135. or config.frontend_port
  136. or constants.DefaultPorts.FRONTEND_PORT
  137. ),
  138. auto_increment=auto_increment_frontend,
  139. )
  140. if backend:
  141. auto_increment_backend = not bool(backend_port or config.backend_port)
  142. backend_port = processes.handle_port(
  143. "backend",
  144. (
  145. backend_port
  146. or config.backend_port
  147. or constants.DefaultPorts.BACKEND_PORT
  148. ),
  149. auto_increment=auto_increment_backend,
  150. )
  151. # Apply the new ports to the config.
  152. if frontend_port != config.frontend_port:
  153. config._set_persistent(frontend_port=frontend_port)
  154. if backend_port != config.backend_port:
  155. config._set_persistent(backend_port=backend_port)
  156. # Reload the config to make sure the env vars are persistent.
  157. get_config(reload=True)
  158. console.rule("[bold]Starting Reflex App")
  159. prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)
  160. # Get the app module.
  161. app_task = prerequisites.compile_or_validate_app
  162. args = (frontend,)
  163. kwargs = {
  164. "check_if_schema_up_to_date": True,
  165. }
  166. # Granian fails if the app is already imported.
  167. if should_use_granian():
  168. import concurrent.futures
  169. compile_future = concurrent.futures.ProcessPoolExecutor(max_workers=1).submit(
  170. app_task,
  171. *args,
  172. **kwargs,
  173. )
  174. validation_result = compile_future.result()
  175. else:
  176. validation_result = app_task(*args, **kwargs)
  177. if not validation_result:
  178. raise click.exceptions.Exit(1)
  179. # Get the frontend and backend commands, based on the environment.
  180. setup_frontend = frontend_cmd = backend_cmd = None
  181. if env == constants.Env.DEV:
  182. setup_frontend, frontend_cmd, backend_cmd = (
  183. build.setup_frontend,
  184. exec.run_frontend,
  185. exec.run_backend,
  186. )
  187. if env == constants.Env.PROD:
  188. setup_frontend, frontend_cmd, backend_cmd = (
  189. build.setup_frontend_prod,
  190. exec.run_frontend_prod,
  191. exec.run_backend_prod,
  192. )
  193. if not setup_frontend or not frontend_cmd or not backend_cmd:
  194. msg = f"Invalid env: {env}. Must be DEV or PROD."
  195. raise ValueError(msg)
  196. # Post a telemetry event.
  197. telemetry.send(f"run-{env.value}")
  198. # Display custom message when there is a keyboard interrupt.
  199. atexit.register(processes.atexit_handler)
  200. # Run the frontend and backend together.
  201. commands = []
  202. # Run the frontend on a separate thread.
  203. if frontend:
  204. setup_frontend(Path.cwd())
  205. commands.append((frontend_cmd, Path.cwd(), frontend_port, backend))
  206. # In prod mode, run the backend on a separate thread.
  207. if backend and env == constants.Env.PROD:
  208. commands.append(
  209. (
  210. backend_cmd,
  211. backend_host,
  212. backend_port,
  213. config.loglevel.subprocess_level(),
  214. frontend,
  215. )
  216. )
  217. # Start the frontend and backend.
  218. with processes.run_concurrently_context(*commands):
  219. # In dev mode, run the backend on the main thread.
  220. if backend and backend_port and env == constants.Env.DEV:
  221. backend_cmd(
  222. backend_host,
  223. int(backend_port),
  224. config.loglevel.subprocess_level(),
  225. frontend,
  226. )
  227. # The windows uvicorn bug workaround
  228. # https://github.com/reflex-dev/reflex/issues/2335
  229. if constants.IS_WINDOWS and exec.frontend_process:
  230. # Sends SIGTERM in windows
  231. exec.kill(exec.frontend_process.pid)
  232. @cli.command()
  233. @loglevel_option
  234. @click.option(
  235. "--env",
  236. type=click.Choice([e.value for e in constants.Env], case_sensitive=False),
  237. default=constants.Env.DEV.value,
  238. help="The environment to run the app in.",
  239. )
  240. @click.option(
  241. "--frontend-only",
  242. is_flag=True,
  243. show_default=False,
  244. help="Execute only frontend.",
  245. envvar=environment.REFLEX_FRONTEND_ONLY.name,
  246. )
  247. @click.option(
  248. "--backend-only",
  249. is_flag=True,
  250. show_default=False,
  251. help="Execute only backend.",
  252. envvar=environment.REFLEX_BACKEND_ONLY.name,
  253. )
  254. @click.option(
  255. "--frontend-port",
  256. type=int,
  257. help="Specify a different frontend port.",
  258. envvar=environment.REFLEX_FRONTEND_PORT.name,
  259. )
  260. @click.option(
  261. "--backend-port",
  262. type=int,
  263. help="Specify a different backend port.",
  264. envvar=environment.REFLEX_BACKEND_PORT.name,
  265. )
  266. @click.option(
  267. "--backend-host",
  268. help="Specify the backend host.",
  269. )
  270. def run(
  271. env: LITERAL_ENV,
  272. frontend_only: bool,
  273. backend_only: bool,
  274. frontend_port: int | None,
  275. backend_port: int | None,
  276. backend_host: str | None,
  277. ):
  278. """Run the app in the current directory."""
  279. if frontend_only and backend_only:
  280. console.error("Cannot use both --frontend-only and --backend-only options.")
  281. raise click.exceptions.Exit(1)
  282. config = get_config()
  283. frontend_port = frontend_port or config.frontend_port
  284. backend_port = backend_port or config.backend_port
  285. backend_host = backend_host or config.backend_host
  286. environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.RUN)
  287. environment.REFLEX_BACKEND_ONLY.set(backend_only)
  288. environment.REFLEX_FRONTEND_ONLY.set(frontend_only)
  289. _run(
  290. constants.Env.DEV if env == constants.Env.DEV else constants.Env.PROD,
  291. frontend_only,
  292. backend_only,
  293. frontend_port,
  294. backend_port,
  295. backend_host,
  296. )
  297. @cli.command()
  298. @loglevel_option
  299. @click.option(
  300. "--dry",
  301. is_flag=True,
  302. default=False,
  303. help="Run the command without making any changes.",
  304. )
  305. def compile(dry: bool):
  306. """Compile the app in the current directory."""
  307. import time
  308. from reflex.utils import prerequisites
  309. # Check the app.
  310. if prerequisites.needs_reinit():
  311. _init(name=get_config().app_name)
  312. get_config(reload=True)
  313. starting_time = time.monotonic()
  314. prerequisites.compile_app(dry_run=dry)
  315. elapsed_time = time.monotonic() - starting_time
  316. console.success(f"App compiled successfully in {elapsed_time:.3f} seconds.")
  317. @cli.command()
  318. @loglevel_option
  319. @click.option(
  320. "--zip/--no-zip",
  321. default=True,
  322. is_flag=True,
  323. help="Whether to zip the backend and frontend exports.",
  324. )
  325. @click.option(
  326. "--frontend-only",
  327. is_flag=True,
  328. show_default=False,
  329. envvar=environment.REFLEX_FRONTEND_ONLY.name,
  330. help="Export only frontend.",
  331. )
  332. @click.option(
  333. "--backend-only",
  334. is_flag=True,
  335. show_default=False,
  336. envvar=environment.REFLEX_BACKEND_ONLY.name,
  337. help="Export only backend.",
  338. )
  339. @click.option(
  340. "--zip-dest-dir",
  341. default=str(Path.cwd()),
  342. help="The directory to export the zip files to.",
  343. show_default=False,
  344. )
  345. @click.option(
  346. "--upload-db-file",
  347. is_flag=True,
  348. help="Whether to exclude sqlite db files when exporting backend.",
  349. hidden=True,
  350. )
  351. @click.option(
  352. "--env",
  353. type=click.Choice([e.value for e in constants.Env], case_sensitive=False),
  354. default=constants.Env.PROD.value,
  355. help="The environment to export the app in.",
  356. )
  357. def export(
  358. zip: bool,
  359. frontend_only: bool,
  360. backend_only: bool,
  361. zip_dest_dir: str,
  362. upload_db_file: bool,
  363. env: LITERAL_ENV,
  364. ):
  365. """Export the app to a zip file."""
  366. from reflex.utils import export as export_utils
  367. from reflex.utils import prerequisites
  368. environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.EXPORT)
  369. should_frontend_run, should_backend_run = prerequisites.check_running_mode(
  370. frontend_only, backend_only
  371. )
  372. config = get_config()
  373. prerequisites.assert_in_reflex_dir()
  374. if should_frontend_run and prerequisites.needs_reinit():
  375. _init(name=config.app_name)
  376. export_utils.export(
  377. zipping=zip,
  378. frontend=should_frontend_run,
  379. backend=should_backend_run,
  380. zip_dest_dir=zip_dest_dir,
  381. upload_db_file=upload_db_file,
  382. env=constants.Env.DEV if env == constants.Env.DEV else constants.Env.PROD,
  383. loglevel=config.loglevel.subprocess_level(),
  384. )
  385. @cli.command()
  386. @loglevel_option
  387. def login():
  388. """Authenticate with experimental Reflex hosting service."""
  389. from reflex_cli.v2 import cli as hosting_cli
  390. from reflex_cli.v2.deployments import check_version
  391. check_version()
  392. validated_info = hosting_cli.login()
  393. if validated_info is not None:
  394. _skip_compile() # Allow running outside of an app dir
  395. telemetry.send("login", user_uuid=validated_info.get("user_id"))
  396. @cli.command()
  397. @loglevel_option
  398. def logout():
  399. """Log out of access to Reflex hosting service."""
  400. from reflex_cli.v2.cli import logout
  401. from reflex_cli.v2.deployments import check_version
  402. check_version()
  403. logout(_convert_reflex_loglevel_to_reflex_cli_loglevel(get_config().loglevel))
  404. @click.group
  405. def db_cli():
  406. """Subcommands for managing the database schema."""
  407. @click.group
  408. def script_cli():
  409. """Subcommands for running helper scripts."""
  410. def _skip_compile():
  411. """Skip the compile step."""
  412. environment.REFLEX_SKIP_COMPILE.set(True)
  413. @db_cli.command(name="init")
  414. def db_init():
  415. """Create database schema and migration configuration."""
  416. from reflex import model
  417. from reflex.utils import prerequisites
  418. config = get_config()
  419. # Check the database url.
  420. if config.db_url is None:
  421. console.error("db_url is not configured, cannot initialize.")
  422. return
  423. # Check the alembic config.
  424. if environment.ALEMBIC_CONFIG.get().exists():
  425. console.error(
  426. "Database is already initialized. Use "
  427. "[bold]reflex db makemigrations[/bold] to create schema change "
  428. "scripts and [bold]reflex db migrate[/bold] to apply migrations "
  429. "to a new or existing database.",
  430. )
  431. return
  432. # Initialize the database.
  433. _skip_compile()
  434. prerequisites.get_compiled_app()
  435. model.Model.alembic_init()
  436. model.Model.migrate(autogenerate=True)
  437. @db_cli.command()
  438. def migrate():
  439. """Create or update database schema from migration scripts."""
  440. from reflex import model
  441. from reflex.utils import prerequisites
  442. prerequisites.get_app()
  443. if not prerequisites.check_db_initialized():
  444. return
  445. model.Model.migrate()
  446. prerequisites.check_schema_up_to_date()
  447. @db_cli.command()
  448. @click.option(
  449. "--message",
  450. help="Human readable identifier for the generated revision.",
  451. )
  452. def makemigrations(message: str | None):
  453. """Create autogenerated alembic migration scripts."""
  454. from alembic.util.exc import CommandError
  455. from reflex import model
  456. from reflex.utils import prerequisites
  457. # TODO see if we can use `get_app()` instead (no compile). Would _skip_compile still be needed then?
  458. _skip_compile()
  459. prerequisites.get_compiled_app()
  460. if not prerequisites.check_db_initialized():
  461. return
  462. with model.Model.get_db_engine().connect() as connection:
  463. try:
  464. model.Model.alembic_autogenerate(connection=connection, message=message)
  465. except CommandError as command_error:
  466. if "Target database is not up to date." not in str(command_error):
  467. raise
  468. console.error(
  469. f"{command_error} Run [bold]reflex db migrate[/bold] to update database."
  470. )
  471. @cli.command()
  472. @loglevel_option
  473. @click.option(
  474. "--app-name",
  475. help="The name of the app to deploy.",
  476. )
  477. @click.option(
  478. "--app-id",
  479. help="The ID of the app to deploy.",
  480. )
  481. @click.option(
  482. "-r",
  483. "--region",
  484. multiple=True,
  485. help="The regions to deploy to. `reflex cloud regions` For multiple envs, repeat this option, e.g. --region sjc --region iad",
  486. )
  487. @click.option(
  488. "--env",
  489. multiple=True,
  490. help="The environment variables to set: <key>=<value>. For multiple envs, repeat this option, e.g. --env k1=v2 --env k2=v2.",
  491. )
  492. @click.option(
  493. "--vmtype",
  494. help="Vm type id. Run `reflex cloud vmtypes` to get options.",
  495. )
  496. @click.option(
  497. "--hostname",
  498. help="The hostname of the frontend.",
  499. )
  500. @click.option(
  501. "--interactive/--no-interactive",
  502. is_flag=True,
  503. default=True,
  504. help="Whether to list configuration options and ask for confirmation.",
  505. )
  506. @click.option(
  507. "--envfile",
  508. help="The path to an env file to use. Will override any envs set manually.",
  509. )
  510. @click.option(
  511. "--project",
  512. help="project id to deploy to",
  513. )
  514. @click.option(
  515. "--project-name",
  516. help="The name of the project to deploy to.",
  517. )
  518. @click.option(
  519. "--token",
  520. help="token to use for auth",
  521. )
  522. @click.option(
  523. "--config-path",
  524. "--config",
  525. help="path to the config file",
  526. )
  527. def deploy(
  528. app_name: str | None,
  529. app_id: str | None,
  530. region: tuple[str, ...],
  531. env: tuple[str],
  532. vmtype: str | None,
  533. hostname: str | None,
  534. interactive: bool,
  535. envfile: str | None,
  536. project: str | None,
  537. project_name: str | None,
  538. token: str | None,
  539. config_path: str | None,
  540. ):
  541. """Deploy the app to the Reflex hosting service."""
  542. from reflex_cli.utils import dependency
  543. from reflex_cli.v2 import cli as hosting_cli
  544. from reflex_cli.v2.deployments import check_version
  545. from reflex.utils import export as export_utils
  546. from reflex.utils import prerequisites
  547. config = get_config()
  548. app_name = app_name or config.app_name
  549. check_version()
  550. environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.DEPLOY)
  551. # Only check requirements if interactive.
  552. # There is user interaction for requirements update.
  553. if interactive:
  554. dependency.check_requirements()
  555. prerequisites.assert_in_reflex_dir()
  556. # Check if we are set up.
  557. if prerequisites.needs_reinit():
  558. _init(name=config.app_name)
  559. prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)
  560. hosting_cli.deploy(
  561. app_name=app_name,
  562. app_id=app_id,
  563. export_fn=(
  564. lambda zip_dest_dir,
  565. api_url,
  566. deploy_url,
  567. frontend,
  568. backend,
  569. upload_db,
  570. zipping: export_utils.export(
  571. zip_dest_dir=zip_dest_dir,
  572. api_url=api_url,
  573. deploy_url=deploy_url,
  574. frontend=frontend,
  575. backend=backend,
  576. zipping=zipping,
  577. loglevel=config.loglevel.subprocess_level(),
  578. upload_db_file=upload_db,
  579. )
  580. ),
  581. regions=list(region),
  582. envs=list(env),
  583. vmtype=vmtype,
  584. envfile=envfile,
  585. hostname=hostname,
  586. interactive=interactive,
  587. loglevel=_convert_reflex_loglevel_to_reflex_cli_loglevel(config.loglevel),
  588. token=token,
  589. project=project,
  590. project_name=project_name,
  591. **({"config_path": config_path} if config_path is not None else {}),
  592. )
  593. @cli.command()
  594. @loglevel_option
  595. @click.argument("new_name")
  596. def rename(new_name: str):
  597. """Rename the app in the current directory."""
  598. from reflex.utils import prerequisites
  599. prerequisites.validate_app_name(new_name)
  600. prerequisites.rename_app(new_name, get_config().loglevel)
  601. if TYPE_CHECKING:
  602. from reflex_cli.constants.base import LogLevel as HostingLogLevel
  603. def _convert_reflex_loglevel_to_reflex_cli_loglevel(
  604. loglevel: constants.LogLevel,
  605. ) -> HostingLogLevel:
  606. """Convert a Reflex log level to a Reflex CLI log level.
  607. Args:
  608. loglevel: The Reflex log level to convert.
  609. Returns:
  610. The converted Reflex CLI log level.
  611. """
  612. from reflex_cli.constants.base import LogLevel as HostingLogLevel
  613. if loglevel == constants.LogLevel.DEBUG:
  614. return HostingLogLevel.DEBUG
  615. if loglevel == constants.LogLevel.INFO:
  616. return HostingLogLevel.INFO
  617. if loglevel == constants.LogLevel.WARNING:
  618. return HostingLogLevel.WARNING
  619. if loglevel == constants.LogLevel.ERROR:
  620. return HostingLogLevel.ERROR
  621. if loglevel == constants.LogLevel.CRITICAL:
  622. return HostingLogLevel.CRITICAL
  623. return HostingLogLevel.INFO
  624. if find_spec("typer") and find_spec("typer.main"):
  625. import typer # pyright: ignore[reportMissingImports]
  626. if isinstance(hosting_cli, typer.Typer):
  627. hosting_cli_command = typer.main.get_command(hosting_cli)
  628. else:
  629. hosting_cli_command = hosting_cli
  630. else:
  631. hosting_cli_command = hosting_cli
  632. cli.add_command(hosting_cli_command, name="cloud")
  633. cli.add_command(db_cli, name="db")
  634. cli.add_command(script_cli, name="script")
  635. cli.add_command(custom_components_cli, name="component")
  636. if __name__ == "__main__":
  637. cli()