mirror of
https://github.com/jo1gi/grawlix.git
synced 2025-12-16 04:09:10 +00:00
Add option to print config path
This commit is contained in:
parent
961789d316
commit
78312371d8
@ -1,5 +1,5 @@
|
||||
from .book import Book, Series
|
||||
from .config import load_config, Config, SourceConfig
|
||||
from .config import load_config, Config, SourceConfig, get_config_path
|
||||
from .exceptions import SourceNotAuthenticated, GrawlixError
|
||||
from .sources import load_source, Source
|
||||
from .output import download_book
|
||||
@ -87,8 +87,18 @@ async def authenticate(source: Source, config: Config, options):
|
||||
raise SourceNotAuthenticated
|
||||
|
||||
|
||||
def run_debug_commands(options) -> None:
|
||||
"""
|
||||
Run optional debug commands if argument is set
|
||||
"""
|
||||
if options.print_config_path:
|
||||
config_path = get_config_path()
|
||||
print(config_path)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
args = arguments.parse_arguments()
|
||||
run_debug_commands(args)
|
||||
config = load_config()
|
||||
logging.debug_mode = args.debug
|
||||
urls = get_urls(args)
|
||||
|
||||
@ -14,6 +14,12 @@ def parse_arguments() -> argparse.Namespace:
|
||||
action = "version",
|
||||
version = f"grawlix {__version__}"
|
||||
)
|
||||
parser.add_argument(
|
||||
'--print-config-path',
|
||||
action = "store_true",
|
||||
help = "Print config path",
|
||||
dest = "print_config_path"
|
||||
)
|
||||
# Basics
|
||||
parser.add_argument(
|
||||
'urls',
|
||||
|
||||
@ -19,14 +19,20 @@ class Config:
|
||||
sources: dict[str, SourceConfig]
|
||||
|
||||
|
||||
def get_config_path() -> str:
|
||||
"""Return the path of the config file"""
|
||||
config_dir = appdirs.user_config_dir("grawlix", "jo1gi")
|
||||
config_file = os.path.join(config_dir, "grawlix.toml")
|
||||
return config_file
|
||||
|
||||
|
||||
def load_config() -> Config:
|
||||
"""
|
||||
Load config from disk
|
||||
|
||||
:returns: Config object
|
||||
"""
|
||||
config_dir = appdirs.user_config_dir("grawlix", "jo1gi")
|
||||
config_file = os.path.join(config_dir, "grawlix.toml")
|
||||
config_file = get_config_path()
|
||||
if os.path.exists(config_file):
|
||||
with open(config_file, "rb") as f:
|
||||
config_dict = tomli.load(f)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user