This commit is contained in:
Jesse Bannon 2026-01-15 20:11:29 -08:00
parent ee2fcc4c1f
commit 93b5a933d9
3 changed files with 44 additions and 14 deletions

View file

@ -15,6 +15,7 @@ from ytdl_sub.cli.output_transaction_log import output_transaction_log
from ytdl_sub.cli.parsers.cli_to_sub import print_cli_to_sub
from ytdl_sub.cli.parsers.dl import DownloadArgsParser
from ytdl_sub.cli.parsers.main import DEFAULT_CONFIG_FILE_NAME
from ytdl_sub.cli.parsers.main import InspectArguments
from ytdl_sub.cli.parsers.main import parser
from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.subscriptions.subscription import Subscription
@ -198,11 +199,32 @@ def _view_url_from_cli(config: ConfigFile, url: str, split_chapters: bool) -> Su
return subscription
def _parse_inspect_mocks(mocks: Optional[List[str]]) -> Dict[str, str]:
out: Dict[str, str] = {}
for mock in mocks or []:
spl = mock.split("=", 1)
if len(spl) == 1:
raise ValidationException("inspect mock must be in the form of VAR=VALUE")
out[spl[0].strip()] = spl[1]
return out
def _parse_inspect_level(inspect_level: str) -> str:
for val, name in InspectArguments.LevelChoices.items():
if inspect_level == val or inspect_level == name:
return name
raise ValueError("should not reach here")
def _inspect(
config: ConfigFile,
subscription_paths: List[str],
subscription_matches: List[str],
subscription_override_dict: Dict,
inspection_level: str,
mocks: Dict[str, str],
) -> None:
subscriptions: List[Subscription] = []
@ -262,6 +284,8 @@ def main() -> List[Subscription]:
subscription_paths=args.subscription_paths,
subscription_matches=args.match,
subscription_override_dict=subscription_override_dict,
inspection_level=_parse_inspect_level(args.inspection_level),
mocks=_parse_inspect_mocks(args.mock),
)
return []

View file

@ -1,5 +1,6 @@
import argparse
import dataclasses
from typing import Dict
from typing import List
from ytdl_sub import __local_version__
@ -235,19 +236,15 @@ class InspectArguments:
short="-l",
long="--level",
)
LevelChoices: List[str] = [
"0",
"original",
"1",
"fill",
"2",
"resolve",
"3",
"internal",
]
LevelChoices: Dict[str, str] = {
"0": "original",
"1": "fill",
"2": "resolve",
"3": "internal",
}
MOCK = CLIArgument(
short="-m",
short="-k",
long="--mock",
)
@ -256,7 +253,7 @@ inspect_parser = subparsers.add_parser("inspect")
inspect_parser.add_argument(
InspectArguments.LEVEL.short,
InspectArguments.LEVEL.long,
metavar="|".join(LoggerLevels.names()),
metavar=",".join(str(i) for i in range(4)),
type=str,
help="""level of inspection to perform:
0 - original present the subscription as-is (default)
@ -265,7 +262,8 @@ inspect_parser.add_argument(
3 - internal resolve all variables to their internal representation
""",
default="0",
choices=InspectArguments.LevelChoices,
choices=list(InspectArguments.LevelChoices.keys())
+ list(InspectArguments.LevelChoices.values()),
dest="inspection_level",
)
inspect_parser.add_argument(
@ -294,3 +292,11 @@ inspect_parser.add_argument(
help="override all subscription config values using `dl` syntax, "
"i.e. --dl-override='--ytdl_options.max_downloads 3'",
)
inspect_parser.add_argument(
InspectArguments.MOCK.short,
InspectArguments.MOCK.long,
metavar="VAR=VALUE",
nargs="+",
help="ability to mock one or more variable values, i.e. --mock 'title=Lets Play'",
)

View file

@ -7,7 +7,7 @@ from ytdl_sub.config.plugin.preset_plugins import PresetPlugins
from ytdl_sub.config.preset_options import OutputOptions
from ytdl_sub.config.validators.options import OptionsValidator
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
from ytdl_sub.validators.string_formatter_validators import validate_formatters, _validate_formatter
from ytdl_sub.validators.string_formatter_validators import validate_formatters
class VariableValidation: