Skip to content

Commit

Permalink
Add --credits flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iafisher committed Mar 5, 2019
1 parent 3214d1e commit 533f636
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Newlines are no longer semi-randomly printed to standard error in preprocessing and assembling mode.

### Added
- The `--credits` flags.

## [0.7.0] - 2019-02-13
### Added
- The `assemble` subcommand, for assembling HERA programs into raw machine code.
Expand Down
18 changes: 18 additions & 0 deletions hera/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ def parse_args(argv: List[str]) -> Settings:
)
sys.exit(1)

if "--credits" in flags:
if len(flags) == 1 and not posargs:
print(CREDITS)
sys.exit(0)
else:
sys.stderr.write(
"--credits may not be combined with other flags or commands.\n"
)
sys.exit(1)

if len(posargs) == 0:
sys.stderr.write("No file path supplied.\n")
sys.exit(1)
Expand Down Expand Up @@ -313,6 +323,7 @@ def bytes_to_hex(b: bytes) -> str:
FLAGS = {
"--big-stack",
"--code",
"--credits",
"--data",
"--help",
"--no-color",
Expand Down Expand Up @@ -340,6 +351,12 @@ def bytes_to_hex(b: bytes) -> str:
}

VERSION = "hera-py 0.7.0 for HERA version 2.4"
CREDITS = (
VERSION
+ """
Developed by Ian Fisher (HC '19) - iafisher@protonmail.com."""
)
HELP = """\
hera: an interpreter for the Haverford Educational RISC Architecture.
Expand All @@ -353,6 +370,7 @@ def bytes_to_hex(b: bytes) -> str:
Common options:
-h, --help Show this message and exit.
-v, --version Show the version and exit.
--credits Print the credits for hera-py development.
--no-color Do not print colored output.
--no-debug-ops Disallow debugging instructions.
Expand Down
9 changes: 9 additions & 0 deletions test/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ def test_no_ANSI_color_when_stderr_is_not_tty():
)


def test_credits_flag(capsys):
with pytest.raises(SystemExit):
main(["--credits"])

captured = capsys.readouterr()
assert captured.err == ""
assert "Ian Fisher" in captured.out


def test_dump_state(capsys):
dump_state(VirtualMachine(), Settings(volume=VOLUME_VERBOSE))

Expand Down

0 comments on commit 533f636

Please sign in to comment.