Skip to content

Commit

Permalink
Support Windows and MacOS (#36)
Browse files Browse the repository at this point in the history
* Support Windows and MacOS

* Add questionary dependency

* Remove the tests

* Remove print
  • Loading branch information
Kludex authored Sep 2, 2021
1 parent ff798ab commit 41648fb
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 432 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: true

Expand Down
34 changes: 8 additions & 26 deletions manage_fastapi/helpers.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
import re
from typing import Tuple, TypeVar
from typing import TypeVar

from bullet import Bullet, SlidePrompt, colors
from bullet.client import YesNo
import questionary

EnumType = TypeVar("EnumType")

WHITE_FOREGROUND = colors.foreground["white"]


def camel_to_snake(text: str) -> str:
return re.sub(r"(?<!^)(?=[A-Z])", "_", text).lower()


def bullet(choices: EnumType) -> Bullet:
def question(choices: EnumType) -> questionary.Question:
prompt = camel_to_snake(choices.__name__).replace("_", " ") # type: ignore
return Bullet(
prompt=f"Select the {prompt}: ",
choices=list(choices), # type: ignore
bullet=" >",
margin=2,
word_color=WHITE_FOREGROUND,
word_on_switch=WHITE_FOREGROUND,
)


def yes_no(option: str) -> YesNo:
return YesNo(
prompt=f"Do you want {option}?", default="n", word_color=WHITE_FOREGROUND
)


def launch_cli(*prompt_objs: Tuple[str, Bullet]):
names, objs = zip(*prompt_objs)
results = SlidePrompt(objs).launch()
return {name: result[1] for name, result in zip(names, results)}
return questionary.select(f"Select the {prompt}: ", choices=list(choices))


def binary_question(option: str) -> questionary.Question:
return questionary.confirm(f"Do you want {option}?", default=False)
17 changes: 9 additions & 8 deletions manage_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import pkg_resources
import typer
from questionary.form import form

from manage_fastapi.constants import Database, License, PackageManager, PythonVersion
from manage_fastapi.context import AppContext, ProjectContext
from manage_fastapi.generator import generate_app, generate_project
from manage_fastapi.helpers import bullet, launch_cli, yes_no
from manage_fastapi.helpers import binary_question, question

app = typer.Typer(
add_completion=False,
Expand All @@ -29,13 +30,13 @@ def startproject(
python: PythonVersion = typer.Option(PythonVersion.THREE_DOT_EIG),
):
if interactive:
result = launch_cli(
("packaging", bullet(PackageManager)),
("python", bullet(PythonVersion)),
("license", bullet(License)),
("pre_commit", yes_no("pre commit")),
("docker", yes_no("docker")),
("database", bullet(Database)),
result = form(
packaging=question(PackageManager),
python=question(PythonVersion),
license=question(License),
pre_commit=binary_question("pre commit"),
docker=binary_question("docker"),
database=question(Database),
)
context = ProjectContext(name=name, **result)
else:
Expand Down
Loading

0 comments on commit 41648fb

Please sign in to comment.