Skip to content

Commit

Permalink
Fix bug creating .hab_user_prefs.json
Browse files Browse the repository at this point in the history
When prompting the user for a URI and the .hab_user_prefs.json file didn't exist, it wouldn't create it.
  • Loading branch information
MHendricks committed Aug 1, 2023
1 parent d1cbaae commit ecaf73c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions hab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class UriArgument(click.Argument):
When using a user pref, a message is written to the error stream to
ensure the user can see what uri was resolved. It is written to the error
stream so it doesn't interfere with capturing output to a file(json).
- If the timestamp on the user_prefs.json is lapse, the user will be prompted
to address the out of date URI by entering a new path or using the already
saved path.
- If the timestamp on the .hab_user_prefs.json is lapse, the user will be
prompted to address the out of date URI by entering a new path or using
the already saved path.
This also handles saving the provided uri to user prefs if enabled by
`SharedSettings.enable_user_prefs_save`. This is only respected if an uri is
Expand Down Expand Up @@ -76,8 +76,12 @@ def type_cast_value(self, ctx, value):
# This will indicate that no user_pref.json was saved
# and the user will be required to enter a uri path.
if uri_check.uri is None:
return self.__uri_prompt()
# Check if the saved user_prefs.json has an expire timestamp
value = self.__uri_prompt()
# Saving a new .hab_user_prefs.json
ctx.obj.resolver.user_prefs().uri = value
click.echo("Saving hab user prefs", err=True)
return value
# Check if the saved .hab_user_prefs.json has an expire timestamp
elif uri_check.timedout:
logger.info(
f"{Fore.RED}Invalid 'URI' preference: {Fore.RESET}"
Expand All @@ -87,9 +91,9 @@ def type_cast_value(self, ctx, value):
# The uri is expired so lets ask the user for a new uri
value = self.__uri_prompt(uri_check.uri)
if value:
# Saving a new user_prefs.json
# Saving an updated .hab_user_prefs.json
ctx.obj.resolver.user_prefs().uri = value
click.echo("Saving user_prefs.json", err=True)
click.echo("Saving hab user prefs", err=True)
return value
else:
if self.required:
Expand All @@ -98,7 +102,7 @@ def type_cast_value(self, ctx, value):
else:
click.echo(
f"Using {Fore.LIGHTBLUE_EX}{uri_check.uri}{Fore.RESET} "
"from user_prefs.json",
"from hab user prefs",
err=True,
)
# Don't allow users to re-save the user prefs value when using
Expand Down

0 comments on commit ecaf73c

Please sign in to comment.