Mercurial > hg > MakeItSo
changeset 189:7d8f3660fabb
fix syntax error and use argparse
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 02 May 2014 10:38:12 -0700 |
parents | 1bcf60bcc455 |
children | 7f48c1e2f523 |
files | makeitso/mkpydir.py setup.py |
diffstat | 2 files changed, 9 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/mkpydir.py Fri Apr 11 18:50:40 2014 -0700 +++ b/makeitso/mkpydir.py Fri May 02 10:38:12 2014 -0700 @@ -4,22 +4,20 @@ make a python module directory with an __init__.py """ -import optparse +import argparse import os import sys def main(args=sys.argv[1:]): + """CLI""" - usage = '%prog [options] directory_name' - parser = optparse.OptionParser(usage=usage, description=__doc__) - options, args = parser.parse_args(args) - if len(args) != 1: - parser.print_usage() - parser.error() + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('directory') + options = parser.parse_args(args) - os.makedirs(args[0]) - init = os.path.join(args[0], '__init__.py') - with f as open(init, 'w'): + os.makedirs(options.directory) + init = os.path.join(options.directory, '__init__.py') + with open(init, 'w') as f: f.write('#\n') if __name__ == '__main__':