1
0
Fork 0
mirror of synced 2024-04-30 10:22:38 +12:00

yaml for options

This commit is contained in:
Piotr Migdal 2022-03-27 20:29:05 +02:00 committed by Serene-Arc
parent 8ab13b4480
commit 798ed728f5
3 changed files with 22 additions and 2 deletions

View file

@ -16,6 +16,7 @@ _common_options = [
click.argument('directory', type=str),
click.option('--authenticate', is_flag=True, default=None),
click.option('--config', type=str, default=None),
click.option('--opts', type=str, default=None),
click.option('--disable-module', multiple=True, default=None, type=str),
click.option('--exclude-id', default=None, multiple=True),
click.option('--exclude-id-file', default=None, multiple=True),

View file

@ -5,6 +5,7 @@ from argparse import Namespace
from typing import Optional
import click
import yaml
class Configuration(Namespace):
@ -12,6 +13,7 @@ class Configuration(Namespace):
super(Configuration, self).__init__()
self.authenticate = False
self.config = None
self.opts: Optional[str] = None
self.directory: str = '.'
self.disable_module: list[str] = []
self.exclude_id = []
@ -49,6 +51,14 @@ class Configuration(Namespace):
self.comment_context: bool = False
def process_click_arguments(self, context: click.Context):
if context.params['opts'] is not None:
with open(context.params['opts']) as f:
opts = yaml.load(f, Loader=yaml.FullLoader)
for arg_key, v in opts.items():
vars(self)[arg_key] = v
for arg_key in context.params.keys():
if arg_key in vars(self) and context.params[arg_key] is not None:
vars(self)[arg_key] = context.params[arg_key]
if arg_key not in vars(self):
continue
if context.params[arg_key] is None or context.params[arg_key] == ():
continue
vars(self)[arg_key] = context.params[arg_key]

9
opts_example.yaml Normal file
View file

@ -0,0 +1,9 @@
skip: [mp4, avi, mov]
file-scheme: "{UPVOTES}_{REDDITOR}_{POSTID}_{DATE}"
limit: 10
sort: top
time: all
no-dupes: true
subreddit:
- EarthPorn
- CityPorn