added argparse class by Steven Bethard
This commit is contained in:
parent
350f6d6f66
commit
bc4c514cbb
27
src/brewserverblocklist/bargparse.py
Normal file
27
src/brewserverblocklist/bargparse.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# SPDX-FileCopyrightText: 2023 Tobias Diekershoff
|
||||
#
|
||||
# SPDX-License-Identifier: CC-BY-SA-2.5
|
||||
|
||||
"""
|
||||
This expansion of the ArgParser class will display the --help results by
|
||||
default if an error occurs (e.g. no arguments are passed to the script).
|
||||
|
||||
It is based on an StackOverflow answer from 2010 by unutbu who refered to
|
||||
a reply from Steven Bethard as source of the code. Postings of that time
|
||||
on StackOverflow are published under the terms of a CreativeCommons license
|
||||
specifically under the CC-BY-SA-2.5 so this module is put under the same
|
||||
license.
|
||||
|
||||
https://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu/4042861#4042861
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
class MyParser(argparse.ArgumentParser):
|
||||
def error(self, message):
|
||||
sys.stderr.write('error: %s\n' % message)
|
||||
self.print_help()
|
||||
sys.exit(2)
|
|
@ -8,11 +8,11 @@ of any number of other Friendica instances.
|
|||
|
||||
See https://git.friendi.ca/tobias/brewserverblocklist
|
||||
"""
|
||||
import argparse
|
||||
import configparser
|
||||
import sys
|
||||
from os.path import exists
|
||||
import requests
|
||||
import bargparse
|
||||
|
||||
class BrewBlocklist():
|
||||
"""
|
||||
|
@ -157,7 +157,7 @@ def main():
|
|||
* collect the ingredient
|
||||
* serve the result
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser = bargparse.MyParser()
|
||||
parser.add_argument('-c', '--config',
|
||||
dest='configfile',
|
||||
required=True,
|
||||
|
|
Loading…
Reference in a new issue