Skip to content

Commit 28e2f78

Browse files
Add --stdout option to write image data directly to stdout while suppressing other output
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 14fe6ee commit 28e2f78

File tree

17 files changed

+61
-34
lines changed

17 files changed

+61
-34
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ The `[global options]` apply to the overarching `git-sim` simulation itself, inc
9292
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
9393
`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation.
9494
`--reverse, -r`: Display commit history in the reverse direction.
95-
`--img-format`: Output format for the image file, i.e. `jpg` or `png`. Default output format is `jpg`.
95+
`--img-format`: Output format for the image file, i.e. `jpg` or `png`. Default output format is `jpg`.
96+
`--stdout`: Write raw image data to stdout while suppressing all other program output.
9697

9798
Animation-only global options (to be used in conjunction with `--animate`):
9899

git_sim/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def main(
9797
help="Output format for the animation files.",
9898
case_sensitive=False,
9999
),
100+
stdout: bool = typer.Option(
101+
settings.stdout,
102+
help="Write raw image data to stdout while suppressing all other program output",
103+
),
100104
):
101105
settings.animate = animate
102106
settings.auto_open = auto_open
@@ -115,6 +119,7 @@ def main(
115119
settings.speed = speed
116120
settings.title = title
117121
settings.video_format = video_format
122+
settings.stdout = stdout
118123

119124

120125
app.command()(git_sim.add.add)

git_sim/add.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def __init__(self, files: list[str]):
2929
sys.exit()
3030

3131
def construct(self):
32-
print(
33-
f"{settings.INFO_STRING} {type(self).__name__.lower()} {' '.join(self.files)}"
34-
)
32+
if not settings.stdout:
33+
print(
34+
f"{settings.INFO_STRING} {type(self).__name__.lower()} {' '.join(self.files)}"
35+
)
3536

3637
self.show_intro()
3738
self.get_commits()

git_sim/animations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ def handle_animations(scene: Scene) -> None:
6868
os.path.join(config.media_dir, "images"), image_file_name
6969
)
7070
cv2.imwrite(image_file_path, image)
71-
print("Output image location:", image_file_path)
71+
if not settings.stdout:
72+
print("Output image location:", image_file_path)
73+
if settings.stdout:
74+
sys.stdout.buffer.write(cv2.imencode(".jpg", image)[1].tobytes())
7275
else:
7376
print("Output video location:", scene.renderer.file_writer.movie_file_path)
7477

75-
if settings.auto_open:
78+
if settings.auto_open and not settings.stdout:
7679
try:
7780
if not settings.animate:
7881
open_file(image_file_path)

git_sim/branch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def __init__(self, name: str):
1212
self.name = name
1313

1414
def construct(self):
15-
print(f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.name}")
15+
if not settings.stdout:
16+
print(f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.name}")
1617

1718
self.show_intro()
1819
self.get_commits()

git_sim/cherrypick.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def __init__(self, commit: str, edit: str):
3434
pass
3535

3636
def construct(self):
37-
print(
38-
f"{settings.INFO_STRING} cherry-pick {self.commit}"
39-
+ ((' -e "' + self.edit + '"') if self.edit else "")
40-
)
37+
if not settings.stdout:
38+
print(
39+
f"{settings.INFO_STRING} cherry-pick {self.commit}"
40+
+ ((' -e "' + self.edit + '"') if self.edit else "")
41+
)
4142

4243
if self.repo.active_branch.name in self.repo.git.branch(
4344
"--contains", self.commit

git_sim/commit.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ def __init__(self, message: str, amend: bool):
3131
sys.exit(1)
3232

3333
def construct(self):
34-
print(
35-
f"{settings.INFO_STRING } {type(self).__name__.lower()} {'--amend ' if self.amend else ''}"
36-
+ '-m "'
37-
+ self.message
38-
+ '"'
39-
)
34+
if not settings.stdout:
35+
print(
36+
f"{settings.INFO_STRING } {type(self).__name__.lower()} {'--amend ' if self.amend else ''}"
37+
+ '-m "'
38+
+ self.message
39+
+ '"'
40+
)
4041

4142
self.show_intro()
4243
self.get_commits()

git_sim/log.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def __init__(self, commits: int):
1616
pass
1717

1818
def construct(self):
19-
print(f"{settings.INFO_STRING} {type(self).__name__.lower()}")
19+
if not settings.stdout:
20+
print(f"{settings.INFO_STRING} {type(self).__name__.lower()}")
2021
self.show_intro()
2122
self.get_commits()
2223
self.parse_commits(self.commits[0])

git_sim/merge.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def __init__(self, branch: str, no_ff: bool):
3737
pass
3838

3939
def construct(self):
40-
print(
41-
f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.branch} {'--no-ff' if self.no_ff else ''}"
42-
)
40+
if not settings.stdout:
41+
print(
42+
f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.branch} {'--no-ff' if self.no_ff else ''}"
43+
)
4344

4445
if self.repo.active_branch.name in self.repo.git.branch(
4546
"--contains", self.branch

git_sim/rebase.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def __init__(self, branch: str):
3434
pass
3535

3636
def construct(self):
37-
print(f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.branch}")
37+
if not settings.stdout:
38+
print(
39+
f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.branch}"
40+
)
3841

3942
if self.branch in self.repo.git.branch(
4043
"--contains", self.repo.active_branch.name

0 commit comments

Comments
 (0)