Prompt for template on reflex init (#2122)
This commit is contained in:
parent
eb52edb067
commit
6e1bce3412
@ -12,4 +12,4 @@ cd /reflex-repo
|
||||
poetry install
|
||||
echo "Running reflex init in test project dir"
|
||||
export TELEMETRY_ENABLED=false
|
||||
poetry run /bin/bash -c "cd ~/hello && reflex init && rm -rf ~/.reflex .web && reflex export --backend-only"
|
||||
poetry run /bin/bash -c "cd ~/hello && reflex init --template blank && rm -rf ~/.reflex .web && reflex export --backend-only"
|
@ -1,5 +1,7 @@
|
||||
"""Reflex CLI to create, run, and deploy apps."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import atexit
|
||||
import json
|
||||
@ -76,8 +78,8 @@ def main(
|
||||
|
||||
def _init(
|
||||
name: str,
|
||||
template: constants.Templates.Kind,
|
||||
loglevel: constants.LogLevel,
|
||||
template: constants.Templates.Kind | None = constants.Templates.Kind.BLANK,
|
||||
loglevel: constants.LogLevel = config.loglevel,
|
||||
):
|
||||
"""Initialize a new Reflex app in the given directory."""
|
||||
# Set the log level.
|
||||
@ -98,6 +100,8 @@ def _init(
|
||||
|
||||
# Set up the app directory, only if the config doesn't exist.
|
||||
if not os.path.exists(constants.Config.FILE):
|
||||
if template is None:
|
||||
template = prerequisites.prompt_for_template()
|
||||
prerequisites.create_config(app_name)
|
||||
prerequisites.initialize_app_directory(app_name, template)
|
||||
telemetry.send("init")
|
||||
@ -120,7 +124,7 @@ def init(
|
||||
None, metavar="APP_NAME", help="The name of the app to initialize."
|
||||
),
|
||||
template: constants.Templates.Kind = typer.Option(
|
||||
constants.Templates.Kind.BLANK.value,
|
||||
None,
|
||||
help="The template to initialize the app with.",
|
||||
),
|
||||
loglevel: constants.LogLevel = typer.Option(
|
||||
|
@ -705,6 +705,35 @@ def check_schema_up_to_date():
|
||||
)
|
||||
|
||||
|
||||
def prompt_for_template() -> constants.Templates.Kind:
|
||||
"""Prompt the user to specify a template.
|
||||
|
||||
Returns:
|
||||
The template the user selected.
|
||||
"""
|
||||
# Show the user the URLs of each temlate to preview.
|
||||
console.print("\nGet started with a template:")
|
||||
console.print("blank (https://blank-template.reflex.run) - A minimal template.")
|
||||
console.print(
|
||||
"sidebar (https://sidebar-template.reflex.run) - A template with a sidebar to navigate pages."
|
||||
)
|
||||
console.print("")
|
||||
|
||||
# Prompt the user to select a template.
|
||||
template = console.ask(
|
||||
"Which template would you like to use?",
|
||||
choices=[
|
||||
template.value
|
||||
for template in constants.Templates.Kind
|
||||
if template.value != "demo"
|
||||
],
|
||||
default=constants.Templates.Kind.BLANK.value,
|
||||
)
|
||||
|
||||
# Return the template.
|
||||
return constants.Templates.Kind(template)
|
||||
|
||||
|
||||
def migrate_to_reflex():
|
||||
"""Migration from Pynecone to Reflex."""
|
||||
# Check if the old config file exists.
|
||||
|
Loading…
Reference in New Issue
Block a user