Added -v or --version option to command line arguments.

This commit is contained in:
Storm Dragon 2024-12-06 02:00:59 -05:00
parent 1d91c62c67
commit 5249f13be9
2 changed files with 63 additions and 14 deletions

View File

@ -4,12 +4,13 @@
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
import signal, time, argparse, sys import signal, time, argparse, os, sys
from fenrirscreenreader.core import i18n from fenrirscreenreader.core import i18n
from fenrirscreenreader.core import settingsManager from fenrirscreenreader.core import settingsManager
from fenrirscreenreader.core import debug from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType from fenrirscreenreader.core.eventData import fenrirEventType
from fenrirscreenreader import fenrirVersion
class fenrirManager(): class fenrirManager():
def __init__(self): def __init__(self):
@ -31,20 +32,69 @@ class fenrirManager():
self.singleKeyCommand = False self.singleKeyCommand = False
self.command = '' self.command = ''
self.setProcessName() self.setProcessName()
def handleArgs(self): def handleArgs(self):
args = None """
parser = argparse.ArgumentParser(description="Fenrir Help") Parse and handle command line arguments for Fenrir.
parser.add_argument('-s', '--setting', metavar='SETTING-FILE', default='/etc/fenrir/settings/settings.conf', help='Use a specified settingsfile')
parser.add_argument('-o', '--options', metavar='SECTION#SETTING=VALUE;..', default='', help='Overwrite options in given settings file. Sections, settings and Values are cases sensitive') Returns:
parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode') argparse.Namespace: Parsed command line arguments
parser.add_argument('-p', '--print', action='store_true', help='Print debug messages on screen') None: If argument parsing fails
parser.add_argument('-e', '--emulated-pty', action='store_true', help='Use PTY emulation and escape sequences for input. Allows to use fenrir on the desktop, in a terminal for X or Wayland') """
parser.add_argument('-E', '--emulated-evdev', action='store_true', help='Use PTY emulation and evdev for input (single instance)') parser = argparse.ArgumentParser(
description="Fenrir - A console screen reader for Linux",
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
'-v', '--version',
action='version',
version=f'Fenrir screen reader version {fenrirVersion.version}',
help='Show version information and exit'
)
parser.add_argument(
'-s', '--setting',
metavar='SETTING-FILE',
default='/etc/fenrir/settings/settings.conf',
help='Path to custom settings file'
)
parser.add_argument(
'-o', '--options',
metavar='SECTION#SETTING=VALUE;..',
default='',
help='Override settings file options. Format: SECTION#SETTING=VALUE;... (case sensitive)'
)
parser.add_argument(
'-d', '--debug',
action='store_true',
help='Enable debug mode'
)
parser.add_argument(
'-p', '--print',
action='store_true',
help='Print debug messages to screen'
)
parser.add_argument(
'-e', '--emulated-pty',
action='store_true',
help='Use PTY emulation with escape sequences for input (enables desktop/X/Wayland usage)'
)
parser.add_argument(
'-E', '--emulated-evdev',
action='store_true',
help='Use PTY emulation with evdev for input (single instance)'
)
try: try:
args = parser.parse_args() args = parser.parse_args()
# Only do format validation, let file existence be handled by the config initialization
if args.options:
for option in args.options.split(';'):
if option and ('#' not in option or '=' not in option):
parser.error(f"Invalid option format: {option}\nExpected format: SECTION#SETTING=VALUE")
if args.emulated_pty and args.emulated_evdev:
parser.error("Cannot use both --emulated-pty and --emulated-evdev simultaneously")
return args
except Exception as e: except Exception as e:
parser.print_help() print(f"Error parsing arguments: {str(e)}", file=sys.stderr)
return args return None
def proceed(self): def proceed(self):
if not self.initialized: if not self.initialized:
return return

View File

@ -4,5 +4,4 @@
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
version = '1.9.7' version = '2024.12'
codename = 'krug'