38 lines
1,012 B
Python
38 lines
1,012 B
Python
import argparse
|
|
import json
|
|
import logging
|
|
import sys
|
|
from typing import Callable
|
|
|
|
from app import app, mirror_sites
|
|
from app.lists.bridgelines import bridgelines
|
|
from app.lists.mirror_mapping import mirror_mapping
|
|
|
|
lists = {
|
|
"mirror_mapping": mirror_mapping,
|
|
"bc2": mirror_sites,
|
|
"bridgelines": bridgelines,
|
|
}
|
|
|
|
|
|
def dump(list_f: Callable):
|
|
json.dump(list_f(), sys.stdout, indent=2)
|
|
|
|
|
|
class ListCliHandler:
|
|
@classmethod
|
|
def add_subparser_to(cls, subparsers: argparse._SubParsersAction) -> None:
|
|
parser = subparsers.add_parser("list", help="list operations")
|
|
parser.add_argument("--dump", choices=sorted(lists.keys()),
|
|
help="dump a list in JSON format")
|
|
parser.set_defaults(cls=cls)
|
|
|
|
def __init__(self, args):
|
|
self.args = args
|
|
|
|
def run(self):
|
|
with app.app_context():
|
|
if self.args.dump:
|
|
dump(lists[self.args.dump])
|
|
else:
|
|
logging.error("No action requested")
|