From af7d21e4737daeb9af04afebce4bd6cb2b824508 Mon Sep 17 00:00:00 2001 From: New Date: Thu, 2 May 2019 03:36:25 +0800 Subject: [PATCH] feat(cli): version & help info --- run.py | 22 ++++++++++++++++------ setup.py | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/run.py b/run.py index 95656e3..d0776a1 100755 --- a/run.py +++ b/run.py @@ -6,8 +6,8 @@ DDNS @modified: rufengsuixing """ from __future__ import print_function -import argparse -import json +from argparse import ArgumentParser, RawTextHelpFormatter +from json import load import time import os import sys @@ -18,6 +18,13 @@ from util import ip from util.cache import Cache __version__ = "python@none-build" +__description__ = "自动更新DNS记录指向本地IP [automatically update DNS records to dynamic local IP]" +__doc__ = """ +ddns[%s] +(i) 文档主页[homepage or docs]: https://ddns.newfuture.cc/ +(?) 问题和帮助[issues or bugs]: https://github.com/NewFuture/DDNS/issues +Copyright (c) New Future ♥ (MIT License) +""" % (__version__) if getattr(sys, 'frozen', False): __version__ = "${BUILD_SOURCEBRANCHNAME}@${BUILD_DATE}" @@ -34,7 +41,7 @@ def get_config(key=None, default=None, path="config.json"): if not hasattr(get_config, "config"): try: with open(path) as configfile: - get_config.config = json.load(configfile) + get_config.config = load(configfile) get_config.time = os.stat(path).st_mtime except IOError: print('Config file %s does not appear to exist.' % path) @@ -128,9 +135,12 @@ def main(): """ 更新 """ - parser = argparse.ArgumentParser() - parser.add_argument('-c', default="config.json") - get_config(path=parser.parse_args().c) + parser = ArgumentParser(description=__description__, + epilog=__doc__, formatter_class=RawTextHelpFormatter) + parser.add_argument('--version', action='version', version=__version__) + parser.add_argument( + '-c', '--config', default="config.json", help="配置文件路径[config file]") + get_config(path=parser.parse_args().config) # Dynamicly import the dns module as configuration dns_provider = str(get_config('dns', 'dnspod').lower()) dns = getattr(__import__('dns', fromlist=[dns_provider]), dns_provider) diff --git a/setup.py b/setup.py index be465db..0bc3789 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ from os import path, environ # and accepts an argument to specify the text encoding # Python 3 only projects can skip this import from io import open +from run import __description__ here = path.abspath(path.dirname(__file__)) @@ -61,7 +62,7 @@ setup( # corresponds to the "Summary" metadata field: # https://packaging.python.org/specifications/core-metadata/#summary # Optional - description='自动更新域名解析到本机IP(支持dnspod,阿里DNS,CloudFlare,DNSCOM...)', + description=__description__, # This is an optional longer description of your project that represents # the body of text which users will see when they visit PyPI.