add help message

This commit is contained in:
leafee98 2022-09-15 15:37:54 +08:00
parent 82456fc05e
commit 43455364e0

View file

@ -4,6 +4,7 @@ import os
import logging import logging
import configparser import configparser
import argparse import argparse
from argparse import RawDescriptionHelpFormatter
from bistu_wifi.bistu_wifi import logger from bistu_wifi.bistu_wifi import logger
from bistu_wifi.bistu_wifi import login from bistu_wifi.bistu_wifi import login
from bistu_wifi.bistu_wifi import logout from bistu_wifi.bistu_wifi import logout
@ -20,8 +21,15 @@ DEFAULT_CONFIG_LOCATION = os.path.join(XDG_CONFIG_HOME, 'bistu-wifi/auth.ini')
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(formatter_class=RawDescriptionHelpFormatter)
parser.description = 'login or logout bistu wifi'
parser.description = 'Login or logout bistu wifi, by sending a post request to authorization host'
parser.epilog = 'The format of config file is like below\n\n' \
' [DEFAULT]\n' \
' username = 202000000\n' \
' password = Bistu000000\n' \
' host = 10.1.206.13\n'
parser.add_argument('-u', '--username', nargs='?', parser.add_argument('-u', '--username', nargs='?',
type=str, help='username you use to login bistu wifi') type=str, help='username you use to login bistu wifi')
@ -32,7 +40,8 @@ def main():
parser.add_argument('-o', '--logout', action='store_true', parser.add_argument('-o', '--logout', action='store_true',
help='logout bistu wifi. try to login if not privided') help='logout bistu wifi. try to login if not privided')
parser.add_argument('-c', '--config', nargs='?', default=DEFAULT_CONFIG_LOCATION, parser.add_argument('-c', '--config', nargs='?', default=DEFAULT_CONFIG_LOCATION,
type=str, help='load info(username, password, host) from config file') type=str, help='load info(username, password, host) from config file. '
f'Will try {DEFAULT_CONFIG_LOCATION} if not provided.')
parser.add_argument('--notime', action='store_true', parser.add_argument('--notime', action='store_true',
help='don\'t output time field in log') help='don\'t output time field in log')