Skip to content

Commit

Permalink
Add defaults for url and domain config options (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Oct 8, 2024
1 parent 95356b2 commit b7d1a6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
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

0 comments on commit b7d1a6c

Please sign in to comment.