Explorar o código

make input more flexible and not require quotes for new players

George C. Privon %!s(int64=8) %!d(string=hai) anos
pai
achega
398deb4a46
Modificáronse 2 ficheiros con 7 adicións e 3 borrados
  1. 1 1
      README.md
  2. 6 2
      update_database.py

+ 1 - 1
README.md

@@ -29,7 +29,7 @@ This launches the interactive shell. Press `?` for a list of commands.
 To update the database (add new players toggle availability of expansions), use the `update_database.py` command. For example, to add a new player:
 
 ```
-$ python update_database.py -n "NEW PLAYER"
+$ python update_database.py -n NEW PLAYER
 ```
 
 Use `python update_database.py -h` to see the full list of options.

+ 6 - 2
update_database.py

@@ -32,6 +32,7 @@ def parseArgs():
     parser = argparse.ArgumentParser(description="Update the Carcassonne \
 scoring database.")
     parser.add_argument('-n', '--newplayer', type=str, default=None,
+                        nargs='+',
                         help='Add a new player.')
     parser.add_argument('-e', '--enableexpansion', action='store_true',
                         default=False,
@@ -56,15 +57,18 @@ def main():
     VALID = False
 
     if args.newplayer:
-        sys.stdout.write("Adding new player: " + args.newplayer)
+        pname = ' '.join(args.newplayer)
+        sys.stdout.write("Adding new player: " + pname)
         sys.stdout.write(" to the database.\n")
         while not VALID:
             ans = input("Is this correct (y/n)? ")
             if re.match('y', ans, re.IGNORECASE):
                 cur.execute('INSERT INTO players (name) VALUES ("' + \
-                            args.newplayer + '")')
+                            pname + '")')
+                sys.stdout.write(pname + ' added to the database.\n')
                 VALID = True
             elif re.match('n', ans, re.IGNORECASE):
+                sys.stdout.write('Canceling.\n')
                 VALID = True
 
     conn.commit()