From 0e5e611d13ab114528838b4ab50b0bf417303877 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 9 Apr 2020 22:57:26 -0700 Subject: [PATCH] Sub-command --- pinch.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pinch.py b/pinch.py index b3f65c6..71496a3 100644 --- a/pinch.py +++ b/pinch.py @@ -1,3 +1,4 @@ +import argparse import configparser import filecmp import functools @@ -7,7 +8,6 @@ import os import os.path import shutil import subprocess -import sys import tempfile import types import urllib.parse @@ -407,10 +407,10 @@ def make_channel(conf: configparser.SectionProxy) -> Channel: return channel -def main(argv: List[str]) -> None: +def pin(args: argparse.Namespace) -> None: v = Verification() config = configparser.ConfigParser() - config.read_file(open(argv[1]), argv[1]) + config.read_file(open(args.channels_file), args.channels_file) for section in config.sections(): channel = make_channel(config[section]) if 'channel_url' in config[section]: @@ -421,8 +421,18 @@ def main(argv: List[str]) -> None: git_fetch(v, channel) config[section]['git_revision'] = channel.git_revision - with open(argv[1], 'w') as configfile: + with open(args.channels_file, 'w') as configfile: config.write(configfile) -main(sys.argv) +def main() -> None: + parser = argparse.ArgumentParser(prog='pinch') + subparsers = parser.add_subparsers(dest='mode', required=True) + parser_pin = subparsers.add_parser('pin') + parser_pin.add_argument('channels_file', type=str) + parser_pin.set_defaults(func=pin) + args = parser.parse_args() + args.func(args) + + +main() -- 2.44.1