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

Add defaults for url and domain config options #301

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions data/mreg-cli.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[mreg]
url=http://127.0.0.1:8000
user=test
domain=example.org
#logfile=cli.log
# url=http://127.0.0.1:8000
# user=test
# domain=example.org
# logfile=cli.log
category_tags=cat1,cat2,cat3
location_tags=loc1,loc2,loc3
6 changes: 3 additions & 3 deletions mreg_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_config_file(self) -> str | None:

def get_default_domain(self):
"""Get the default domain from the application."""
return self.get("domain")
return self.get("domain", "uio.no")

def get_default_logfile(self):
"""Get the default logfile from the application."""
Expand All @@ -213,8 +213,8 @@ def get_category_tags(self) -> list[str]:
# it cannot be none once options, env, and config file are parsed.
def get_url(self) -> str:
"""Get the default url from the application."""
url = self.get("url", self.get("default_url"))
if url is None:
url = self.get("url", self.get("default_url", "https://mreg.uio.no"))
if not url:
raise ValueError("No URL found in config, no defaults available!")
return url

Expand Down
11 changes: 1 addition & 10 deletions mreg_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ def main():

parser = argparse.ArgumentParser(description="The MREG cli")

# Accept empty url as the default option for the --url parameter.
# If the user never sets the URL we will throw a value error on
# the initial connection attempt.
default_url = ""
try:
default_url = config.get_url()
except ValueError:
pass

parser.add_argument(
"--version",
help="Show version and exit.",
Expand All @@ -46,7 +37,7 @@ def main():
connect_args = parser.add_argument_group("connection settings")
connect_args.add_argument(
"--url",
default=default_url,
default=config.get_url(),
help="use mreg server at %(metavar)s (default: %(default)s)",
metavar="URL",
)
Expand Down