Skip to content

Commit 6e1bce3

Browse files
authored
Prompt for template on reflex init (#2122)
1 parent eb52edb commit 6e1bce3

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

integration/init-test/in_docker_test_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ cd /reflex-repo
1212
poetry install
1313
echo "Running reflex init in test project dir"
1414
export TELEMETRY_ENABLED=false
15-
poetry run /bin/bash -c "cd ~/hello && reflex init && rm -rf ~/.reflex .web && reflex export --backend-only"
15+
poetry run /bin/bash -c "cd ~/hello && reflex init --template blank && rm -rf ~/.reflex .web && reflex export --backend-only"

reflex/reflex.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Reflex CLI to create, run, and deploy apps."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import atexit
57
import json
@@ -76,8 +78,8 @@ def main(
7678

7779
def _init(
7880
name: str,
79-
template: constants.Templates.Kind,
80-
loglevel: constants.LogLevel,
81+
template: constants.Templates.Kind | None = constants.Templates.Kind.BLANK,
82+
loglevel: constants.LogLevel = config.loglevel,
8183
):
8284
"""Initialize a new Reflex app in the given directory."""
8385
# Set the log level.
@@ -98,6 +100,8 @@ def _init(
98100

99101
# Set up the app directory, only if the config doesn't exist.
100102
if not os.path.exists(constants.Config.FILE):
103+
if template is None:
104+
template = prerequisites.prompt_for_template()
101105
prerequisites.create_config(app_name)
102106
prerequisites.initialize_app_directory(app_name, template)
103107
telemetry.send("init")
@@ -120,7 +124,7 @@ def init(
120124
None, metavar="APP_NAME", help="The name of the app to initialize."
121125
),
122126
template: constants.Templates.Kind = typer.Option(
123-
constants.Templates.Kind.BLANK.value,
127+
None,
124128
help="The template to initialize the app with.",
125129
),
126130
loglevel: constants.LogLevel = typer.Option(

reflex/utils/prerequisites.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,35 @@ def check_schema_up_to_date():
705705
)
706706

707707

708+
def prompt_for_template() -> constants.Templates.Kind:
709+
"""Prompt the user to specify a template.
710+
711+
Returns:
712+
The template the user selected.
713+
"""
714+
# Show the user the URLs of each temlate to preview.
715+
console.print("\nGet started with a template:")
716+
console.print("blank (https://blank-template.reflex.run) - A minimal template.")
717+
console.print(
718+
"sidebar (https://sidebar-template.reflex.run) - A template with a sidebar to navigate pages."
719+
)
720+
console.print("")
721+
722+
# Prompt the user to select a template.
723+
template = console.ask(
724+
"Which template would you like to use?",
725+
choices=[
726+
template.value
727+
for template in constants.Templates.Kind
728+
if template.value != "demo"
729+
],
730+
default=constants.Templates.Kind.BLANK.value,
731+
)
732+
733+
# Return the template.
734+
return constants.Templates.Kind(template)
735+
736+
708737
def migrate_to_reflex():
709738
"""Migration from Pynecone to Reflex."""
710739
# Check if the old config file exists.

0 commit comments

Comments
 (0)