Making arguments positional and removing the "usage" functions
All these arguments were required and might as well be positional thusly. If you don't provide all required positional arguments, argparser will correct you and request usage.
This commit is contained in:
parent
7f4b44710b
commit
8781ddb541
@ -1,23 +1,17 @@
|
||||
import os
|
||||
|
||||
from mediagoblin.gmg_commands import util as commands_util
|
||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
||||
from mediagoblin.auth import lib as auth_lib
|
||||
from mediagoblin import mg_globals
|
||||
|
||||
def adduser_usage():
|
||||
print '\nUsage: adduser -u username -p password -m email'
|
||||
|
||||
|
||||
def adduser_parser_setup(subparser):
|
||||
subparser.add_argument(
|
||||
'-u', '--username',
|
||||
'username',
|
||||
help="Username used to login")
|
||||
subparser.add_argument(
|
||||
'-p', '--password',
|
||||
'password',
|
||||
help="Your supersecret word to login")
|
||||
subparser.add_argument(
|
||||
'-m', '--email',
|
||||
'email',
|
||||
help="Email to recieve notifications")
|
||||
subparser.add_argument(
|
||||
'-cf', '--conf_file', default='mediagoblin.ini',
|
||||
@ -26,17 +20,7 @@ def adduser_parser_setup(subparser):
|
||||
|
||||
def adduser(args):
|
||||
#TODO: Lets trust admins this do not validate Emails :)
|
||||
if args.username == None :
|
||||
print 'You must provide an username'
|
||||
adduser_usage()
|
||||
elif args.password == None:
|
||||
print 'You must provide a password'
|
||||
adduser_usage()
|
||||
elif args.email == None:
|
||||
print 'You must provide an email'
|
||||
adduser_usage()
|
||||
else:
|
||||
mgoblin_app = commands_util.setup_app(args)
|
||||
commands_util.setup_app(args)
|
||||
|
||||
db = mg_globals.database
|
||||
users_with_username = \
|
||||
@ -59,13 +43,9 @@ def adduser(args):
|
||||
print "User Created: Already Verified :)"
|
||||
|
||||
|
||||
def makeadmin_usage():
|
||||
print '\nUsage: makeadmin -u username'
|
||||
|
||||
|
||||
def makeadmin_parser_setup(subparser):
|
||||
subparser.add_argument(
|
||||
'-u', '--username',
|
||||
'username',
|
||||
help="Username to give admin level")
|
||||
subparser.add_argument(
|
||||
'-cf', '--conf_file', default='mediagoblin.ini',
|
||||
@ -73,11 +53,7 @@ def makeadmin_parser_setup(subparser):
|
||||
|
||||
|
||||
def makeadmin(args):
|
||||
if args.username == None:
|
||||
print 'You must provide an username'
|
||||
makeadmin_usage()
|
||||
else:
|
||||
mgoblin_app = commands_util.setup_app(args)
|
||||
commands_util.setup_app(args)
|
||||
|
||||
db = mg_globals.database
|
||||
|
||||
@ -90,16 +66,12 @@ def makeadmin(args):
|
||||
print 'The user doesn\'t exist'
|
||||
|
||||
|
||||
def changepw_usage():
|
||||
print '\nUsage: changepw -u username -p new_password'
|
||||
|
||||
|
||||
def changepw_parser_setup(subparser):
|
||||
subparser.add_argument(
|
||||
'-u', '--username',
|
||||
'username',
|
||||
help="Username used to login")
|
||||
subparser.add_argument(
|
||||
'-p', '--password',
|
||||
'password',
|
||||
help="Your NEW supersecret word to login")
|
||||
subparser.add_argument(
|
||||
'-cf', '--conf_file', default='mediagoblin.ini',
|
||||
@ -107,14 +79,7 @@ def changepw_parser_setup(subparser):
|
||||
|
||||
|
||||
def changepw(args):
|
||||
if args.username == None:
|
||||
print 'You must provide an username'
|
||||
adduser_usage()
|
||||
elif args.password == None:
|
||||
print 'You must provide a password'
|
||||
adduser_usage()
|
||||
else:
|
||||
mgoblin_app = commands_util.setup_app(args)
|
||||
commands_util.setup_app(args)
|
||||
|
||||
db = mg_globals.database
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user