Skip to content

Commit ae55bed

Browse files
committed
feat: add rebase_todo_injector_command
1 parent dcbb328 commit ae55bed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

grading_lib/cli/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import click
24

35
from ..util import get_problem_total_points, load_problems_metadata
@@ -37,5 +39,35 @@ def summary_command() -> None:
3739
print(f" - {name:<40} {score_section:>20}")
3840

3941

42+
@cli.command(name="rebase-todo-injector")
43+
@click.argument("todo_items_file_path")
44+
@click.argument("path")
45+
def rebase_todo_injector_command(todo_items_file_path, path) -> None:
46+
"""
47+
An 'editor' that inject pre-made todo items for git interactive rebase.
48+
49+
It assumes that the pre-made todo items file is named 'rebase-todo-items.txt'
50+
and it is in the current working directory.
51+
52+
This command cannot be used directly, you want to create a script file that call
53+
this command.
54+
55+
Example script file:
56+
#!/bin/bash
57+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
58+
python -m grading_lib rebase-todo-injector $SCRIPT_DIR/../rebase-todo-items.txt $1
59+
"""
60+
todo_items_file_path = Path(todo_items_file_path)
61+
if not todo_items_file_path.exists():
62+
raise FileNotFoundError(
63+
f"Cannot find '{todo_items_file_path}' in the current working directory (cwd='{Path(".").absolute()}')"
64+
)
65+
with open(todo_items_file_path) as in_f:
66+
todo_items_content = in_f.read()
67+
68+
with open(path, "w") as out_f:
69+
out_f.write(todo_items_content)
70+
71+
4072
cli.add_command(dev)
4173
cli.add_command(internal)

0 commit comments

Comments
 (0)