Skip to content

Commit

Permalink
added version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasTar committed Nov 22, 2024
1 parent 262e8fd commit 37e732c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@ cython_debug/
*.code-workspace
/.vscode
/test
/builds/build_temps
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This tool has a few features executed via command-line flags. In its simplest fo
You can always run the tool with the flag `-h` for info about each flag.

``` title="Usage command"
converter.py inputFile [-h] [-a] [-c] [-pix]
converter.py inputFile [-h] [-v | --version] [-a] [-c] [-pix]
[-wi INTEGER | -wc INTEGER]
[-hi INTEGER | -hc INTEGER]
[-gsc {10,70} (def: 70)]
Expand All @@ -59,6 +59,7 @@ converter.py inputFile [-h] [-a] [-c] [-pix]
| Flag | Long Flag | Description | Value type | Implemented |
| :----- | :----------------- | :-------------------------------------------------------------------------------------- | :------------------------ | :---------: |
| `-h` | `--help` | Displays a help message with more info. | Bool ||
| `-v` | `--version` | Displays the current version of the app. | Bool ||
| `-a` | `--auto` | Figures out the usage parameters automatically from the input | Bool ||
| `-c` | `--colored` | Output text will be colored instead of grayscale. Used for XML or image output formats. | Bool ||
| `-wi` | `--width` | Custom tile Width in pixels. | Integer ||
Expand Down
2 changes: 1 addition & 1 deletion converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# https://en.wikipedia.org/wiki/ASCII_art#:~:text=of%20Unicode.-,Methods%20for%20generating%20ASCII%20art

from src import frontend
from src.tools import APP_VERSION

APP_VERSION = "1.0.0"

def main():
print(f"\n{"=-=-"*18}")
Expand Down
20 changes: 18 additions & 2 deletions src/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setupParser() -> None:

# TODO somehow make these dynamic
usage = dedent(
'converter.py inputFile [-h] [-a] [-c] [-pix] \n\
'converter.py inputFile [-h] [-v | --version] [-a] [-c] [-pix] \n\
[-wi INTEGER | -wc INTEGER] \n\
[-hi INTEGER | -hc INTEGER] \n\
[-gsc {10,70} (def: 70)] \n\
Expand Down Expand Up @@ -107,6 +107,13 @@ def pSetupArguments() -> None:
action = 'store_true',
help = 'Should the program decide the values on its own? NOT IMPLEMENTED'
)
parser.add_argument( # version of the app
'-v', '--version',
dest = 'versionRequested',
required = False,
action = 'store_true',
help = 'The version of the app'
)

# ========= Mechanism Flags ========

Expand Down Expand Up @@ -225,10 +232,18 @@ def runTool(shouldSave: bool = False): # TODO implement shouldSave, if false ret
If some flags are not set, it will request them from the user.
If that cant be done, it will exit with an error message.
'''
args = parser.parse_args()

try:
args = parser.parse_args()
except:
exitWith("Invalid input")

inputArguments = InputArguments

if args.versionRequested:
print(f"\nVersion: {tools.APP_VERSION}")
exitWith()

try:
inputArguments.inputFileImage = Image.open(args.inputFile)
except FileNotFoundError:
Expand Down Expand Up @@ -368,6 +383,7 @@ def exitWith(error: Exception | str | None = None) -> NoReturn:
print(f"\n{"-="*18} ERROR {"=-"*18}=\n\nDuring processing, program encountered an error with the message:\n\t{error}\n\n{"-="*40}\n")
# Non zero exit code indicates something went wrong
code = 1
input("\nPress 'Enter' to exit...\n")
print("\nTool is exiting...\n")
exit(code)

Expand Down
2 changes: 2 additions & 0 deletions src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# NOTE consider having the params be a global struct or something using this:
# https://stackoverflow.com/questions/35988/c-like-structures-in-python

APP_VERSION = "1.0.0"

class Errors:
class GenericError(Exception):

Expand Down

0 comments on commit 37e732c

Please sign in to comment.