Merge pull request #6 from htgoebel/issue-5
Add minimal argparse support to get support for `--help`.
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
import yaml
|
import yaml
|
||||||
import dateutil
|
import dateutil
|
||||||
import feedparser
|
import feedparser
|
||||||
@ -9,8 +10,17 @@ import feedparser
|
|||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_FILE = os.path.join("~", ".feediverse")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config_file = get_config_file()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("config_file", nargs="?", metavar="CONFIG-FILE",
|
||||||
|
help=("config file to use, default: %s" %
|
||||||
|
DEFAULT_CONFIG_FILE),
|
||||||
|
default=os.path.expanduser(DEFAULT_CONFIG_FILE))
|
||||||
|
args = parser.parse_args()
|
||||||
|
config_file = args.config_file
|
||||||
|
|
||||||
if not os.path.isfile(config_file):
|
if not os.path.isfile(config_file):
|
||||||
setup(config_file)
|
setup(config_file)
|
||||||
|
|
||||||
@ -29,13 +39,6 @@ def main():
|
|||||||
|
|
||||||
save_config(config, config_file)
|
save_config(config, config_file)
|
||||||
|
|
||||||
def get_config_file():
|
|
||||||
if __name__ == "__main__" and len(sys.argv) > 1:
|
|
||||||
config_file = sys.argv[1]
|
|
||||||
else:
|
|
||||||
config_file = os.path.join(os.path.expanduser("~"), ".feediverse")
|
|
||||||
return config_file
|
|
||||||
|
|
||||||
def save_config(config, config_file):
|
def save_config(config, config_file):
|
||||||
copy = dict(config)
|
copy = dict(config)
|
||||||
copy['updated'] = datetime.now(tz=timezone.utc).isoformat()
|
copy['updated'] = datetime.now(tz=timezone.utc).isoformat()
|
||||||
|
|||||||
Reference in New Issue
Block a user