Skip to content

Commit

Permalink
update argparse functions
Browse files Browse the repository at this point in the history
use generic 'FaithLife' b/c env var is not likely to be set

split up cli parsing and arg parsing

update help text to reflect current handling
  • Loading branch information
n8marti committed Jan 2, 2024
1 parent 148cdbe commit 4899411
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions LogosLinuxInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
from wine import run_winetricks
from wine import switch_logging


def parse_command_line():
parser = argparse.ArgumentParser(description=f'Installs {os.environ.get("FLPRODUCT")} Bible Software with Wine on Linux.')
parser = argparse.ArgumentParser(description=f'Installs FaithLife Bible Software with Wine on Linux.')
parser.add_argument('--version', '-v', action='version', version=f'{config.LOGOS_SCRIPT_TITLE}, {config.LOGOS_SCRIPT_VERSION} by {config.LOGOS_SCRIPT_AUTHOR}')
parser.add_argument('--config', '-c', metavar='CONFIG_FILE', help='Use the Logos on Linux config file when setting environment variables. Defaults to ~/.config/Logos_on_Linux/Logos_on_Linux.conf. Optionally can accept a config file provided by the user.')
parser.add_argument('--config', '-c', metavar='CONFIG_FILE', help=f'Use a custom Logos on Linux config file during installation. Default config is at {config.DEFAULT_CONFIG_PATH}.')
parser.add_argument('--verbose', '-V', action='store_true', help='Enable verbose mode')
parser.add_argument('--skip-fonts', '-F', action='store_true', help='Skip font installations')
parser.add_argument('--force-root', '-f', action='store_true', help='Set LOGOS_FORCE_ROOT to true, which permits the root user to use the script.')
Expand All @@ -53,9 +54,9 @@ def parse_command_line():
parser.add_argument('--shortcut', '-s', action='store_true', help='Create shortcut')
parser.add_argument('--passive', '-P', action='store_true', help='Install Faithlife product non-interactively')
parser.add_argument('--control-panel', '-C', action='store_true', help='Open Control Panel app')
return parser.parse_args()

args = parser.parse_args()

def parse_args(args):
if args.config:
config.CONFIG_FILE = args.config
config.set_config_env(config.CONFIG_FILE)
Expand Down Expand Up @@ -116,6 +117,8 @@ def restore():
pass

def main():
cli_args = parse_command_line()

die_if_running()
die_if_root()

Expand All @@ -124,12 +127,17 @@ def main():
# Update config from CONFIG_FILE.
# FIXME: This means that values in CONFIG_FILE take precedence over env variables.
# Is this preferred, or should env variables take precedence over CONFIG_FILE?
if file_exists(config.CONFIG_FILE):
config.set_config_env(config.CONFIG_FILE)
config_file = config.CONFIG_FILE
if file_exists(config.LEGACY_CONFIG_FILE):
config_file = config.LEGACY_CONFIG_FILE
config.set_config_env(config_file)

# Update logging level from config.
logger = logging.getLogger()
logger.setLevel(config.LOG_LEVEL)

parse_command_line()
parse_args(cli_args)

# Configure logging.
if config.DELETE_INSTALL_LOG and os.path.isfile(config.LOGOS_LOG):
os.remove(config.LOGOS_LOG)
initialize_logging(config.LOG_LEVEL)
Expand Down

0 comments on commit 4899411

Please sign in to comment.