use argparse

This commit is contained in:
j 2017-06-15 08:57:53 +02:00
parent 1a489dc229
commit 49a30d0c43

View file

@ -6,7 +6,8 @@ from __future__ import print_function
import os import os
import sys import sys
from optparse import OptionParser from argparse import ArgumentParser
import json import json
@ -18,14 +19,16 @@ if os.path.exists(os.path.join(root, 'pandora_client')):
import pandora_client import pandora_client
if __name__ == '__main__': if __name__ == '__main__':
usage = "usage: %prog [options] action" usage = "usage: %(prog)s [options] action"
parser = OptionParser(usage=usage) parser = ArgumentParser(usage=usage)
parser.add_option('-v', '--version', dest='version', action="store_true") parser.add_argument('-v', '--version', dest='version', action="store_true")
parser.add_option('-c', '--config', dest='config', parser.add_argument('-c', '--config', dest='config',
help='config.json containing config', default='~/.ox/client.json', type='string') help='config.json containing config', default='~/.ox/client.json')
parser.add_option('-d', '--debug', dest='debug', parser.add_argument('-d', '--debug', dest='debug',
help='output debug information', action="store_true") help='output debug information', action="store_true")
(opts, args) = parser.parse_args() parser.add_argument('files', metavar='path', type=str, nargs='*', help='files or hashes')
opts = parser.parse_args()
args = opts.files
if opts.version: if opts.version:
print("%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__)) print("%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__))