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
# 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 settingsManager
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType
from fenrirscreenreader import fenrirVersion
class fenrirManager():
def __init__(self):
@ -31,20 +32,69 @@ class fenrirManager():
self.singleKeyCommand = False
self.command = ''
self.setProcessName()
def handleArgs(self):
args = None
parser = argparse.ArgumentParser(description="Fenrir Help")
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')
parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode')
parser.add_argument('-p', '--print', action='store_true', help='Print debug messages on screen')
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)')
def handleArgs(self):
"""
Parse and handle command line arguments for Fenrir.
Returns:
argparse.Namespace: Parsed command line arguments
None: If argument parsing fails
"""
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:
args = parser.parse_args()
except Exception as e:
parser.print_help()
# 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:
print(f"Error parsing arguments: {str(e)}", file=sys.stderr)
return None
def proceed(self):
if not self.initialized:
return

View File

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