Skip to content

Commit

Permalink
added command line option to specify an alternative configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-kaiser committed Mar 20, 2024
1 parent e1cb3d7 commit 3039693
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions appimage/startapp.py
Expand Up @@ -135,10 +135,10 @@ def entry_points(self) -> Dict[str, EntryPoint]:

def get_entry_point(self, *, ignore_default: bool = False) -> Optional[EntryPoint]:

if self.argv0 and self.argv0 in self.entry_points:
return self.entry_points[self.argv0]
if self.env_ep and self.env_ep in self.entry_points:
return self.entry_points[self.env_ep]
if self.argv0 and self.argv0 in self.entry_points:
return self.entry_points[self.argv0]
if (
not ignore_default
and self.default_ep
Expand Down
21 changes: 21 additions & 0 deletions sshmitm/moduleparser.py
Expand Up @@ -21,6 +21,7 @@
import inspect
import logging
import sys
import os
from abc import ABC, abstractmethod
from importlib import import_module
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union, cast
Expand Down Expand Up @@ -389,6 +390,9 @@ def _split_lines(self, text: str, width: int) -> List[str]:
class ModuleParser(
_ModuleArgumentParser
): # pylint: disable=too-many-instance-attributes

CONFIG_LOADED = False

def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-arguments
kwargs["formatter_class"] = ModuleFormatter
super().__init__(add_help=False, **kwargs)
Expand All @@ -398,6 +402,23 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-arguments
self.plugin_group = self.add_argument_group(self.config_section)
self.subcommand: Optional["argparse._SubParsersAction[ModuleParser]"] = None
self._registered_subcommands: Dict[str, SubCommand] = {}
self.add_config_arg()

def add_config_arg(self) -> None:
self.add_argument(
"--config", dest="config_path", help="path to a configuration file"
)
if ModuleParser.CONFIG_LOADED:
return
config_path_parser = argparse.ArgumentParser(add_help=False)
config_path_parser.add_argument("--config", dest="config_path")
args, _ = config_path_parser.parse_known_args()
if not args.config_path:
return
if not os.path.isfile(args.config_path):
logging.error("failed to load config file: %s", args.config_path)
return
CONFIGFILE.read(os.path.expanduser(args.config_path))

def load_subcommands(self) -> None:
if not self.subcommand:
Expand Down

0 comments on commit 3039693

Please sign in to comment.