yaml for options
This commit is contained in:
parent
8ab13b4480
commit
798ed728f5
|
@ -16,6 +16,7 @@ _common_options = [
|
||||||
click.argument('directory', type=str),
|
click.argument('directory', type=str),
|
||||||
click.option('--authenticate', is_flag=True, default=None),
|
click.option('--authenticate', is_flag=True, default=None),
|
||||||
click.option('--config', type=str, 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('--disable-module', multiple=True, default=None, type=str),
|
||||||
click.option('--exclude-id', default=None, multiple=True),
|
click.option('--exclude-id', default=None, multiple=True),
|
||||||
click.option('--exclude-id-file', default=None, multiple=True),
|
click.option('--exclude-id-file', default=None, multiple=True),
|
||||||
|
|
|
@ -5,6 +5,7 @@ from argparse import Namespace
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class Configuration(Namespace):
|
class Configuration(Namespace):
|
||||||
|
@ -12,6 +13,7 @@ class Configuration(Namespace):
|
||||||
super(Configuration, self).__init__()
|
super(Configuration, self).__init__()
|
||||||
self.authenticate = False
|
self.authenticate = False
|
||||||
self.config = None
|
self.config = None
|
||||||
|
self.opts: Optional[str] = None
|
||||||
self.directory: str = '.'
|
self.directory: str = '.'
|
||||||
self.disable_module: list[str] = []
|
self.disable_module: list[str] = []
|
||||||
self.exclude_id = []
|
self.exclude_id = []
|
||||||
|
@ -49,6 +51,14 @@ class Configuration(Namespace):
|
||||||
self.comment_context: bool = False
|
self.comment_context: bool = False
|
||||||
|
|
||||||
def process_click_arguments(self, context: click.Context):
|
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():
|
for arg_key in context.params.keys():
|
||||||
if arg_key in vars(self) and context.params[arg_key] is not None:
|
if arg_key not in vars(self):
|
||||||
vars(self)[arg_key] = context.params[arg_key]
|
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
9
opts_example.yaml
Normal 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
|
Loading…
Reference in a new issue