lists: fix mirror mapping output
This commit is contained in:
parent
481e60fa45
commit
8960f8904c
3 changed files with 41 additions and 1 deletions
38
app/cli/list.py
Normal file
38
app/cli/list.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
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")
|
Loading…
Add table
Add a link
Reference in a new issue