Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use config file for redbot_cli #301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/redbot_cli
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __author__ = "Jerome Renard <[email protected]>"
from configparser import ConfigParser
from argparse import ArgumentParser
import sys
import os

import thor

Expand Down Expand Up @@ -45,7 +46,7 @@ def main() -> None:
args = parser.parse_args()

config_parser = ConfigParser()
config_parser.read_dict({"redbot": {"lang": "en", "charset": "utf-8"}})
config_parser.read(os.environ.get("REDBOT_CONFIG", "config.txt"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it'd be better to use $XDG_CONFIG_HOME, defaulting to $HOME/.config as per the spec.

Something like:

Suggested change
config_parser.read(os.environ.get("REDBOT_CONFIG", "config.txt"))
home_dir = os.environ.get("HOME")
config_dir = os.environ.get("XDG_CONFIG_HOME", f"{home_dir}/.config")
config_loc = f"{config_dir}/redbot.cfg"
if os.path.exists(config_loc):
config_parser.read(config_loc)
else:
config_parser.read_dict({"redbot": {"lang": "en", "charset": "utf-8"}})

(not tested)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied how to read the config file from https://github.com/mnot/redbot/blob/main/bin/redbot_cgi.py#L82
I guess both ways are fine, but it is probably least confusing if all files use the same mechanism to read the config file.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redbot_cgi.py is no more, so that shouldn't be an issue any more.

config = config_parser["redbot"]

resource = HttpResource(config, descend=args.descend)
Expand Down