Skip to content

Refactor with typer #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ python -m venv .venv
source .venv/bin/activate
just install
```

## Usage

![image](screenshot.png)
![image](screenshot2.png)
![image](screenshot3.png)
1 change: 0 additions & 1 deletion django_mongodb_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

dm = typer.Typer(
help=help_text,
add_completion=False,
context_settings={"help_option_names": ["-h", "--help"]},
)

Expand Down
107 changes: 103 additions & 4 deletions django_mongodb_cli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ def status(
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Show status of all repos"
),
reset: bool = typer.Option(
False, "--reset", "-r", help="Reset the status of the repository"
),
):
repo = Repo()
if reset:
repo.set_reset(reset)
repo_command(
all_repos,
repo_name,
all_msg="Showing status for all repositories...",
missing_msg="Please specify a repository name or use --all-repos to show all repositories.",
single_func=lambda name: Repo().get_repo_status(name),
all_func=lambda name: Repo().get_repo_status(name),
single_func=lambda name: repo.get_repo_status(name),
all_func=lambda name: repo.get_repo_status(name),
)


Expand Down Expand Up @@ -106,6 +112,30 @@ def clone_repo(name):
)


@repo.command()
def commit(
repo_name: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Commit all repositories"
),
message: str = typer.Argument(None, help="Commit message"),
):
def do_commit(name):
if not message:
typer.echo(typer.style("Commit message is required.", fg=typer.colors.RED))
raise typer.Exit(1)
Repo().commit_repo(name, message)

repo_command(
all_repos,
repo_name,
all_msg="Committing all repositories...",
missing_msg="Please specify a repository name or use --all-repos to commit all repositories.",
single_func=do_commit,
all_func=do_commit,
)


@repo.command()
def delete(
repo_name: str = typer.Argument(None),
Expand Down Expand Up @@ -149,20 +179,75 @@ def install(
)


@repo.command()
def log(
repo_name: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Show logs of all repositories"
),
):
repo_command(
all_repos,
repo_name,
all_msg="Showing logs for all repositories...",
missing_msg="Please specify a repository name or use --all-repos to show logs of all repositories.",
single_func=lambda name: Repo().get_repo_log(repo_name),
all_func=lambda name: Repo().get_repo_log(repo_name),
)


@repo.command()
def open(
repo_name: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Open all repositories"
),
):
repo_command(
all_repos,
repo_name,
all_msg="Opening all repositories...",
missing_msg="Please specify a repository name or use --all-repos to open all repositories.",
single_func=lambda name: Repo().open_repo(repo_name),
all_func=lambda name: Repo().open_repo(repo_name),
)


@repo.command()
def origin(
repo_name: str = typer.Argument(None),
repo_user: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Show origin of all repositories"
),
):
repo = Repo()
if repo_user:
repo.set_user(repo_user)
repo_command(
all_repos,
repo_name,
all_msg="Showing origin for all repositories...",
missing_msg="Please specify a repository name or use --all-repos to show origins of all repositories.",
single_func=lambda name: Repo().get_repo_origin(name),
all_func=lambda name: Repo().get_repo_origin(name),
single_func=lambda name: repo.get_repo_origin(name),
all_func=lambda name: repo.get_repo_origin(name),
)


@repo.command()
def pr(
repo_name: str = typer.Argument(None),
all_repos: bool = typer.Option(
False, "--all-repos", "-a", help="Create pull requests for all repositories"
),
):
repo_command(
all_repos,
repo_name,
all_msg="Creating pull requests for all repositories...",
missing_msg="Please specify a repository name or use --all-repos to create pull requests for all repositories.",
single_func=lambda name: Repo().create_pr(repo_name),
all_func=lambda name: Repo().create_pr(repo_name),
)


Expand All @@ -183,6 +268,20 @@ def sync(
)


@repo.command()
def patch(
repo_name: str = typer.Argument(None),
):
repo_command(
False,
repo_name,
all_msg="Running evergreen...",
missing_msg="Please specify a repository name.",
single_func=lambda name: Test().patch_repo(name),
all_func=lambda name: Test().patch_repo(name),
)


@repo.command()
def test(
repo_name: str = typer.Argument(None),
Expand Down
Loading