Last active
May 21, 2018 11:26
-
-
Save MOOOWOOO/7bf8941509a656df339459ef11350312 to your computer and use it in GitHub Desktop.
argparse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin python | |
# coding: utf-8 | |
import sys | |
from argparse import ArgumentParser | |
from os.path import exists | |
def main(*args): | |
start = args[0].start | |
end = args[0].end | |
return start, end | |
def check_file(file_path): | |
return True if exists(file_path) else False | |
def init_arg_list(argument_paser): | |
argument_paser.add_argument('-s', | |
'--start', | |
help='start date', | |
action='store') # 配置数据源文件,即备份的用户配置 | |
argument_paser.add_argument('-e', | |
'--end', | |
help='end date', | |
action='store') # 配置数据目标文件,即新版本用到的配置文件 | |
def check_args(argument_paser): | |
if len(sys.argv) == 1: | |
argument_paser.print_help() | |
sys.exit(1) | |
if __name__ == "__main__": | |
ap = ArgumentParser() | |
init_arg_list(ap) | |
check_args(ap) | |
args, remaining = ap.parse_known_args(sys.argv) | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment