Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312202

Change subject: [IMPR] Simplify arg parsing
......................................................................

[IMPR] Simplify arg parsing

Change-Id: If4d9038781d2e702d78bebf11b16c4a8460b250a
---
M scripts/welcome.py
1 file changed, 30 insertions(+), 48 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/02/312202/1

diff --git a/scripts/welcome.py b/scripts/welcome.py
index 0f2f908..cc6693d 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -893,30 +893,23 @@
     @type args: list of unicode
     """
     for arg in pywikibot.handle_args(args):
-        if arg.startswith('-edit'):
-            if len(arg) == 5:
-                globalvar.attachEditCount = int(pywikibot.input(
-                    u'After how many edits would you like to welcome new 
users? (0 is allowed)'))
-            else:
-                globalvar.attachEditCount = int(arg[6:])
-        elif arg.startswith('-timeoffset'):
-            if len(arg) == 11:
-                globalvar.timeoffset = int(pywikibot.input(
-                    'Which time offset (in minutes) for new users would you 
like to use?'))
-            else:
-                globalvar.timeoffset = int(arg[12:])
-        elif arg.startswith('-time'):
-            if len(arg) == 5:
-                globalvar.timeRecur = int(pywikibot.input(
-                    u'For how many seconds would you like to bot to sleep 
before checking again?'))
-            else:
-                globalvar.timeRecur = int(arg[6:])
-        elif arg.startswith('-offset'):
-            if len(arg) == 7:
-                val = pywikibot.input(
-                    'Which time offset for new users would you like to use? 
(yyyymmddhhmmss)')
-            else:
-                val = arg[8:]
+        arg, sep, value = arg.partition(':')
+        if arg == '-edit':
+            globalvar.attachEditCount = int(val or pywikibot.input(
+                'After how many edits would you like to welcome new users? '
+                '(0 is allowed)'))
+        elif arg == '-timeoffset':
+            globalvar.timeoffset = int(val or pywikibot.input(
+                'Which time offset (in minutes) for new users would you like '
+                'to use?'))
+        elif arg == '-time':
+            globalvar.timeRecur = int(val or pywikibot.input(
+                'For how many seconds would you like to bot to sleep before '
+                'checking again?'))
+        elif arg == '-offset':
+            globalvar.offset = int(val or pywikibot.input(
+                'Which time offset for new users would you like to use? '
+                '(yyyymmddhhmmss)'))
             try:
                 globalvar.offset = pywikibot.Timestamp.fromtimestampformat(val)
             except ValueError:
@@ -926,19 +919,13 @@
                     "anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP "
                     "is yyyymmddhhmmss. -timeoffset is now also supported. "
                     "Please read this script source header for documentation.")
-        elif arg.startswith('-file'):
+        elif arg == '-file':
             globalvar.randomSign = True
-            if len(arg) <= 6:
-                globalvar.signFileName = pywikibot.input(
-                    u'Where have you saved your signatures?')
-            else:
-                globalvar.signFileName = arg[6:]
-        elif arg.startswith('-sign'):
-            if len(arg) <= 6:
-                globalvar.defaultSign = pywikibot.input(
-                    u'Which signature to use?')
-            else:
-                globalvar.defaultSign = arg[6:]
+            globalvar.signFileName = val or pywikibot.input(
+                u'Where have you saved your signatures?')
+        elif arg == '-sign':
+            globalvar.defaultSign = val or pywikibot.input(
+                u'Which signature to use?')
             globalvar.defaultSign += timeselected
         elif arg == '-break':
             globalvar.recursive = False
@@ -954,18 +941,13 @@
             globalvar.randomSign = True
         elif arg == '-sul':
             globalvar.welcomeAuto = True
-        elif arg.startswith('-limit'):
-            if len(arg) == 6:
-                globalvar.queryLimit = int(pywikibot.input(
-                    u'How many of the latest new users would you like to 
load?'))
-            else:
-                globalvar.queryLimit = int(arg[7:])
-        elif arg.startswith('-numberlog'):
-            if len(arg) == 10:
-                globalvar.dumpToLog = int(pywikibot.input(
-                    u'After how many welcomed users would you like to update 
the welcome log?'))
-            else:
-                globalvar.dumpToLog = int(arg[11:])
+        elif arg == '-limit':
+            globalvar.queryLimit = int(val or pywikibot.input(
+                u'How many of the latest new users would you like to load?'))
+        elif arg == '-numberlog':
+            globalvar.dumpToLog = int(val or pywikibot.input(
+                'After how many welcomed users would you like to update the '
+                'welcome log?'))
         elif arg == '-quiet':
             globalvar.quiet = True
         elif arg == '-quick':

-- 
To view, visit https://gerrit.wikimedia.org/r/312202
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4d9038781d2e702d78bebf11b16c4a8460b250a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to