From f392ea79caf5f7b99cd405d5300e4f9e089c9b91 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Feb 19 2016 17:41:40 +0000 Subject: When cwd contains just one spec file, just use it At least with dist-git there's almost always just one spec file in given directory, so there's no need to force the user to give the name. --- diff --git a/spectool b/spectool index 31d44be..0e3178a 100755 --- a/spectool +++ b/spectool @@ -1,6 +1,7 @@ #!/usr/bin/python3 import argparse import operator +import glob import re import sys from subprocess import CalledProcessError, PIPE, Popen, TimeoutExpired @@ -196,7 +197,7 @@ def parseopts(): epilog="Files:\n/etc/rpmdevrools/curlrc\n optional curl(1) configuration", formatter_class=argparse.RawDescriptionHelpFormatter, add_help=False) - parser.add_argument('spec', help='The specfile to be parsed') + parser.add_argument('spec', help='The specfile to be parsed', nargs='?') mode = parser.add_argument_group('Operating mode') mode1 = mode.add_mutually_exclusive_group() @@ -241,6 +242,16 @@ def parseopts(): opts = parser.parse_args() + if opts.spec is None: + files = glob.glob('*.spec') + if not files: + print("Spec-file was not specified and current directory does not contain any") + sys.exit(1) + if len(files) > 1: + print("Spec-file was not specified and current directory contains multiple") + sys.exit(1) + opts.spec = files[0] + # Can argparse do this for me? if opts.allsources or opts.allpatches: opts.all = False