summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 11:52:20 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 11:52:20 -0400
commit56b965b2e30d483145a737062151616a3628960c (patch)
tree7be920499024f71bb2bed31a0afe19ae43872077
parentafd622604f9ec4360d50b6e32b11fc66e44d62a1 (diff)
downloadb4-56b965b2e30d483145a737062151616a3628960c.tar.gz
Switch ty -s and -d to allow friendly ranges
Instead of insisting that people put in specific numbers, allow them to specify ranges, such as: b4 ty -s 1-3,5,7- Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py18
-rw-r--r--b4/command.py8
-rw-r--r--b4/ty.py12
3 files changed, 28 insertions, 10 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index a6b683e..a7fb436 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1904,3 +1904,21 @@ def make_quote(body, maxlines=5):
quotelines.append('> %s' % line.rstrip())
qcount += 1
return '\n'.join(quotelines)
+
+
+def parse_int_range(intrange, upper=None):
+ # Remove all whitespace
+ intrange = re.sub(r'\s', '', intrange)
+ for n in intrange.split(','):
+ if n.isdigit():
+ yield int(n)
+ elif n.find('<') == 0 and len(n) > 1 and n[1:].isdigit():
+ yield from range(0, int(n[1:]))
+ elif n.find('-') > 0:
+ nr = n.split('-')
+ if nr[0].isdigit() and nr[1].isdigit():
+ yield from range(int(nr[0]), int(nr[1])+1)
+ elif not len(nr[1]) and nr[0].isdigit() and upper:
+ yield from range(int(nr[0]), upper+1)
+ else:
+ logger.critical('Unknown range value specified: %s', n)
diff --git a/b4/command.py b/b4/command.py
index 54b79f5..72a2fe1 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -148,10 +148,10 @@ def cmd():
help='Write thanks files into this dir (default=.)')
sp_ty.add_argument('-l', '--list', action='store_true', default=False,
help='List pull requests and patch series you have retrieved')
- sp_ty.add_argument('-s', '--send', nargs='+',
- help='Generate thankyous for specified messages (use -l to get the list or "all")')
- sp_ty.add_argument('-d', '--discard', nargs='+',
- help='Discard specified messages (use -l to get the list, or use "all")')
+ sp_ty.add_argument('-s', '--send', default=None,
+ help='Generate thankyous for specific entries from -l (e.g.: 1,3-5,7-; or "all")')
+ sp_ty.add_argument('-d', '--discard', default=None,
+ help='Discard specific messages from -l (e.g.: 1,3-5,7-; or "all")')
sp_ty.add_argument('-a', '--auto', action='store_true', default=False,
help='Use the Auto-Thankanator to figure out what got applied/merged')
sp_ty.add_argument('-b', '--branch', default=None,
diff --git a/b4/ty.py b/b4/ty.py
index 33baddb..82cc02f 100644
--- a/b4/ty.py
+++ b/b4/ty.py
@@ -450,11 +450,11 @@ def send_selected(cmdargs):
logger.info('Nothing to do')
sys.exit(0)
- if 'all' in cmdargs.send:
+ if cmdargs.send == 'all':
listing = tracked
else:
listing = list()
- for num in cmdargs.send:
+ for num in b4.parse_int_range(cmdargs.send, upper=len(tracked)):
try:
index = int(num) - 1
listing.append(tracked[index])
@@ -483,11 +483,11 @@ def discard_selected(cmdargs):
logger.info('Nothing to do')
sys.exit(0)
- if 'all' in cmdargs.discard:
+ if cmdargs.discard == 'all':
listing = tracked
else:
listing = list()
- for num in cmdargs.discard:
+ for num in b4.parse_int_range(cmdargs.discard, upper=len(tracked)):
try:
index = int(num) - 1
listing.append(tracked[index])
@@ -612,5 +612,5 @@ def main(cmdargs):
sys.exit(0)
write_tracked(tracked)
logger.info('---')
- logger.info('You can send them using:')
- logger.info(' b4 ty -s 1 [2 3 ...]')
+ logger.info('You can send them using number ranges, e.g:')
+ logger.info(' b4 ty -s 1-3,5,7-')