-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_command_line_arguments.py
More file actions
61 lines (42 loc) · 1.23 KB
/
Copy pathget_command_line_arguments.py
File metadata and controls
61 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Python argparse example for a web server manager.
"""
import argparse
def init_app(config):
return app
def runserver(args):
pass
def syncdb(args):
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Manage application')
# Includes '-h' option to show help messages
parser.add_argument('-c', '--config',
dest='config',
default='settings',
type=str,
help='Config file to load settings from'
)
# Start creating sub-commands
subparsers = parser.add_subparsers()
# runserver starts a DEVELOPMENT server (do NOT use in production)
runserver_parser = subparsers.add_parser('runserver', help='Launch server')
runserver_parser.set_defaults(func=runserver)
runserver_parser.add_argument('-H', '--host',
dest='host',
default='localhost',
type=str,
help='Host to start the server on'
)
runserver_parser.add_argument('-p', '--port',
dest='port',
default=80,
type=int,
help='Port number to start the server on'
)
# syncdb creates the models in the database
syncdb_parser = subparsers.add_parser('syncdb', help='Create database from models')
syncdb_parser.set_defaults(func=syncdb)
# Parse arguments and perform the specified command
args = parser.parse_args()
args.func(args)