reflex.py 21 KB

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