Skip to content

Commit

Permalink
Prompt for template on reflex init (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo committed Nov 3, 2023
1 parent eb52edb commit 6e1bce3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integration/init-test/in_docker_test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 7 additions & 3 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Reflex CLI to create, run, and deploy apps."""

from __future__ import annotations

import asyncio
import atexit
import json
Expand Down Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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(
Expand Down
29 changes: 29 additions & 0 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6e1bce3

Please sign in to comment.