Skip to content

Use Typer instead of argparse #49

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 27 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3f19d5a
first draft for typer commands
paketb0te Jan 27, 2023
2d54992
make each command a separate typer app
paketb0te Feb 1, 2023
3abea68
remove implemented options from TODO comment
paketb0te Feb 1, 2023
c2c595e
add logo, show_intro, show_outro, media_dir
paketb0te Feb 3, 2023
0794f68
finish top-level options
paketb0te Feb 7, 2023
d6a06af
make log a command instead of a typr app
paketb0te Feb 7, 2023
ed313b0
move print statement into GitSimBaseCommand
paketb0te Feb 7, 2023
7ed7a0b
remove dupplicate setting "logo"
paketb0te Feb 7, 2023
c9cb296
make status a command instead of a typr app
paketb0te Feb 7, 2023
8c4c940
Revert "move print statement into GitSimBaseCommand"
paketb0te Feb 7, 2023
295865a
add "add"
paketb0te Feb 7, 2023
e4c7ce0
add "restore"
paketb0te Feb 7, 2023
a6bdff0
add "commit"
paketb0te Feb 7, 2023
e2b740f
add "stash"
paketb0te Feb 7, 2023
6e94570
add "branch"
paketb0te Feb 7, 2023
3d089c2
add "tag"
paketb0te Feb 7, 2023
c066631
update class name for branch
paketb0te Feb 7, 2023
0f95e59
add "reset"
paketb0te Feb 7, 2023
d405db3
rebase onto v0.2.2
paketb0te Feb 7, 2023
4fdce76
add "revert"
paketb0te Feb 8, 2023
6897614
add "merge"
paketb0te Feb 8, 2023
4d65620
add "rebase"
paketb0te Feb 8, 2023
49efb82
add "cherrypick"
paketb0te Feb 8, 2023
c52da38
clean up __main__.py and animations.py
paketb0te Feb 8, 2023
0b2db4c
remove obsolete self.maxrefs
paketb0te Feb 9, 2023
8a7c547
move all changes back into the original files
paketb0te Feb 9, 2023
7a747b6
update deps in setup.py
paketb0te Feb 9, 2023
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
Prev Previous commit
Next Next commit
add "cherrypick"
  • Loading branch information
paketb0te committed Feb 8, 2023
commit 49efb82358ae6c7630ca969dc2820afe77468560
21 changes: 2 additions & 19 deletions git_sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import git_sim.add
import git_sim.branch
import git_sim.cherrypick
import git_sim.commit
import git_sim.log
import git_sim.merge
Expand All @@ -30,6 +31,7 @@
app.command()(git_sim.restore.restore)
app.command()(git_sim.commit.commit)
app.command()(git_sim.stash.stash)
app.command()(git_sim.cherrypick.cherrypick)
app.command()(git_sim.branch.branch)
app.command()(git_sim.tag.tag)
app.command()(git_sim.reset.reset)
Expand Down Expand Up @@ -138,25 +140,6 @@ def main(
# )


# subparsers = parser.add_subparsers(dest="subcommand", help="subcommand help")


# cherrypick = subparsers.add_parser("cherry-pick", help="cherry-pick -h")
# cherrypick.add_argument(
# "commit",
# nargs=1,
# type=str,
# help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch",
# )

# cherrypick.add_argument(
# "-e",
# "--edit",
# help="Specify a new commit message for the cherry-picked commit",
# type=str,
# )


# if len(sys.argv) == 1:
# parser.print_help()
# sys.exit(1)
Expand Down
84 changes: 84 additions & 0 deletions git_sim/cherrypick.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import sys

import git
import manim as m
import typer

from git_sim.animations import handle_animations
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import Settings


class CherryPick(GitSimBaseCommand):
def __init__(self, commit: str, edit: str):
super().__init__()
self.commit = commit
self.edit = edit

try:
git.repo.fun.rev_parse(self.repo, self.commit)
except git.exc.BadName:
print(
"git-sim error: '"
+ self.commit
+ "' is not a valid Git ref or identifier."
)
sys.exit(1)

if self.commit in [branch.name for branch in self.repo.heads]:
self.selected_branches.append(self.commit)

try:
self.selected_branches.append(self.repo.active_branch.name)
except TypeError:
pass

def construct(self):
substring = ""
if self.edit:
substring = f' -e "{self.edit}"'
print(f"{Settings.INFO_STRING} cherrypick {self.commit}{substring}")

if self.repo.active_branch.name in self.repo.git.branch(
"--contains", self.commit
):
print(
"git-sim error: Commit '"
+ self.commit
+ "' is already included in the history of active branch '"
+ self.repo.active_branch.name
+ "'."
)
sys.exit(1)

self.show_intro()
self.get_commits()
self.parse_commits(self.commits[0])
self.orig_commits = self.commits
self.get_commits(start=self.commit)
self.parse_commits(self.commits[0], shift=4 * m.DOWN)
self.center_frame_on_commit(self.orig_commits[0])
self.setup_and_draw_parent(
self.orig_commits[0],
self.edit if self.edit else self.commits[0].message,
)
self.draw_arrow_between_commits(self.commits[0].hexsha, "abcdef")
self.recenter_frame()
self.scale_frame()
self.reset_head_branch("abcdef")
self.fadeout()
self.show_outro()


def cherrypick(
commit: str = typer.Argument(
...,
help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch",
),
edit: str = typer.Option(
default=None,
help="Specify a new commit message for the cherry-picked commit",
),
):
scene = CherryPick(commit=commit, edit=edit)
handle_animations(scene=scene)