zulip_botserver: Migrate from optparse to argparse.
This commit is contained in:
		
							parent
							
								
									8fbb3700d2
								
							
						
					
					
						commit
						de23a1b32f
					
				
					 1 changed files with 17 additions and 17 deletions
				
			
		|  | @ -4,7 +4,7 @@ from __future__ import print_function | ||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
| import json | import json | ||||||
| import optparse | import argparse | ||||||
| from flask import Flask, request | from flask import Flask, request | ||||||
| from importlib import import_module | from importlib import import_module | ||||||
| from typing import Any, Dict, Mapping, Union, List, Tuple | from typing import Any, Dict, Mapping, Union, List, Tuple | ||||||
|  | @ -80,7 +80,7 @@ def handle_bot(bot): | ||||||
|     return json.dumps("") |     return json.dumps("") | ||||||
| 
 | 
 | ||||||
| def parse_args(): | def parse_args(): | ||||||
|     # type: () -> Tuple[Any, Any] |     # type: () -> Tuple[Any] | ||||||
|     usage = ''' |     usage = ''' | ||||||
|             zulip-bot-server --config-file <path to flaskbotrc> --hostname <address> --port <port> |             zulip-bot-server --config-file <path to flaskbotrc> --hostname <address> --port <port> | ||||||
|             Example: zulip-bot-server --config-file ~/flaskbotrc |             Example: zulip-bot-server --config-file ~/flaskbotrc | ||||||
|  | @ -95,27 +95,27 @@ def parse_args(): | ||||||
|             See lib/readme.md for more context. |             See lib/readme.md for more context. | ||||||
|             ''' |             ''' | ||||||
| 
 | 
 | ||||||
|     parser = optparse.OptionParser(usage=usage) |     parser = argparse.ArgumentParser(usage=usage) | ||||||
|     parser.add_option('--config-file', |     parser.add_argument('--config-file', | ||||||
|                       action='store', |                         action='store', | ||||||
|                       help='(config file for the zulip bot server (flaskbotrc))') |                         help='(config file for the zulip bot server (flaskbotrc))') | ||||||
|     parser.add_option('--hostname', |     parser.add_argument('--hostname', | ||||||
|                       action='store', |                         action='store', | ||||||
|                       default="127.0.0.1", |                         default="127.0.0.1", | ||||||
|                       help='(address on which you want to run the server)') |                         help='(address on which you want to run the server)') | ||||||
|     parser.add_option('--port', |     parser.add_argument('--port', | ||||||
|                       action='store', |                         action='store', | ||||||
|                       default=5002, |                         default=5002, | ||||||
|                       help='(port on which you want to run the server)') |                         help='(port on which you want to run the server)') | ||||||
|     (options, args) = parser.parse_args() |     options = parser.parse_args() | ||||||
|     if not options.config_file:  # if flaskbotrc is not given |     if not options.config_file:  # if flaskbotrc is not given | ||||||
|         parser.error('Flaskbotrc not given') |         parser.error('Flaskbotrc not given') | ||||||
|     return (options, args) |     return options | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|     # type: () -> None |     # type: () -> None | ||||||
|     (options, args) = parse_args() |     options = parse_args() | ||||||
|     read_config_file(options.config_file) |     read_config_file(options.config_file) | ||||||
|     global available_bots |     global available_bots | ||||||
|     available_bots = list(bots_config.keys()) |     available_bots = list(bots_config.keys()) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Eeshan Garg
						Eeshan Garg