Use new betterhelp.

master
voussoir 2022-02-12 19:51:36 -08:00
parent a308c10767
commit 31de5d0dfa
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 65 additions and 42 deletions

View File

@ -483,39 +483,6 @@ def zip_directory(path):
# COMMAND LINE #####################################################################################
DOCSTRING = '''
simpleserver
============
Run a simple file server from your computer.
> simpleserver port <flags>
port:
Port number, an integer.
flags:
--password X:
A password string. The user will be prompted to enter it before proceeding
to any URL. A token is stored in a cookie unless authorize_by_ip is used.
--authorize_by_ip:
After the user enters the password, their entire IP becomes authorized for
all future requests. This reduces security, because a single IP can be home
to many different people, but increases convenience, because the user can
use download managers / scripts where adding auth is not convenient.
--enable_zip:
Add a 'zip' link to every directory and allow the user to download the
entire directory as a zip file.
--overall_ratelimit X:
An integer number of bytes, the maximum bytes/sec of the server overall.
--individual_ratelimit X:
An integer number of bytes, the maximum bytes/sec for any single request.
'''
def simpleserver_argparse(args):
server = SimpleServer(
port=args.port,
@ -528,17 +495,73 @@ def simpleserver_argparse(args):
server.start()
def main(argv):
parser = argparse.ArgumentParser(description=DOCSTRING)
parser.add_argument('port', nargs='?', type=int, default=40000)
parser.add_argument('--password', dest='password', default=None)
parser.add_argument('--authorize_by_ip', '--authorize-by-ip', dest='authorize_by_ip', action='store_true')
parser.add_argument('--enable_zip', '--enable-zip', dest='enable_zip', action='store_true')
parser.add_argument('--overall_ratelimit', '--overall-ratelimit', type=bytestring.parsebytes, default=20*bytestring.MIBIBYTE)
parser.add_argument('--individual_ratelimit', '--individual-ratelimit', type=bytestring.parsebytes, default=10*bytestring.MIBIBYTE)
parser = argparse.ArgumentParser(
description=
'''
Run a simple http file server from your computer.
''',
)
parser.examples = [
'4242 --password letmeinplease --authorize-by-ip --enable-zip',
'--individual-ratelimit 2m --overall-ratelimit 10m',
]
parser.add_argument(
'port',
nargs='?',
type=int,
default=40000,
)
parser.add_argument(
'--password',
dest='password',
type=str,
default=None,
help='''
A password string. The user will be prompted to enter it before proceeding
to any URL. A token is stored in a cookie unless authorize_by_ip is used.
''',
)
parser.add_argument(
'--authorize_by_ip',
'--authorize-by-ip',
action='store_true',
help='''
After the user enters the password, their entire IP becomes authorized for
all future requests. This reduces security, because a single IP can be home
to many different people, but increases convenience, because the user can
use download managers / scripts where adding auth is not convenient.
''',
)
parser.add_argument(
'--enable_zip',
'--enable-zip',
action='store_true',
help='''
Add a 'zip' link to every directory and allow the user to download the
entire directory as a zip file.
''',
)
parser.add_argument(
'--overall_ratelimit',
'--overall-ratelimit',
type=bytestring.parsebytes,
default=20*bytestring.MIBIBYTE,
help='''
The maximum bytes/sec of the server overall.
''',
)
parser.add_argument(
'--individual_ratelimit',
'--individual-ratelimit',
type=bytestring.parsebytes,
default=10*bytestring.MIBIBYTE,
help='''
The maximum bytes/sec for any single request.
''',
)
parser.set_defaults(func=simpleserver_argparse)
return betterhelp.single_main(argv, parser, DOCSTRING)
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))