feat(cli): version & help info

This commit is contained in:
New
2019-05-02 03:36:25 +08:00
parent ce133d3672
commit af7d21e473
2 changed files with 18 additions and 7 deletions
+16 -6
View File
@@ -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)
+2 -1
View File
@@ -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.