Skip to content

Commit

Permalink
Added opts: -w(rite-config) and help, version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimdeekepler committed Mar 12, 2024
1 parent 23bfc9e commit 4bcf9ac
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions scrolltext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,55 @@
from scrolltext.utils import init_utils


HELP = """\
scrolltext [-w|--write] action
-w|--write write initial config
action cursestext or linescroller
"""
VERSION = "scrolltext v0.0.8" # possible improvement: use importlib metadata?


def main():
"""
Main method.
"""
action = _parse_args()
write_config, action = _parse_args()
try:
cfg = init_utils(False)
cfg = init_utils(write_config)
action = action or _str_to_action_type(cfg["main"]["action"])
action(False)
action(write_config)
except NameError as e:
print("NameError occured: " + str(e))
print("Probalby check config?")


def _parse_args(): # pylint: disable=inconsistent-return-statements (R1710)
write_config = False
action = None
for arg in sys.argv[1:]:
if "cursestext" == arg:
if _check_help_or_version(arg):
sys.exit(0)

if arg in ["-w", "--write"]:
write_config = True
elif "cursestext" == arg:
action = cursesscroller
elif "linescroller" == arg:
action = linescroller
return action
return write_config, action


def _check_help_or_version(arg):
if arg in ["-h", "--help"]:
print(HELP)
return True
if arg in ["-v", "--version"]:
print(VERSION)
return True
return False


def _str_to_action_type(action):
Expand Down

0 comments on commit 4bcf9ac

Please sign in to comment.