Mercurial > hg > bitsyblog
diff bitsyblog/cli.py @ 102:bc08a00a7d93
make user creation work again, wip
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Feb 2014 16:50:06 -0800 |
parents | dd4abe56edf7 |
children |
line wrap: on
line diff
--- a/bitsyblog/cli.py Sat Feb 01 13:19:26 2014 -0800 +++ b/bitsyblog/cli.py Sun Feb 23 16:50:06 2014 -0800 @@ -1,28 +1,37 @@ #!/usr/bin/env python """ -command line interface to bitsyblog +bitsyblog command line interface for user creation """ -import optparse +import argparse import sys +from getpass import getpass from user import FilespaceUsers def main(args=sys.argv[1:]): - """command line entry point for user creation""" # command line parser - usage = '%prog [options] directory user' - parser = optparse.OptionParser(usage=usage) - options, args = parser.parse_args(args) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('directory', help="base bitsyblog user directory") + parser.add_argument('user', help="user name") + parser.add_argument('-p', '--password', dest='password', + help="password for user") + options = parser.parse_args(args) - # get user name - if len(args) != 2: - parser.error("directory, user not specified") - directory, name = args + # read password if not given + if not options.password: + password = getpass("Enter password for {} : ".format(options.user)) + if password: + options.password = password + else: + parser.error("No password given") - # create user - users = FilespaceUsers(directory) + # create userspace + users = FilespaceUsers(options.directory) + + # create a user + # TODO: password hashing if __name__ == '__main__': main()