Skip to content

Commit

Permalink
Add set-uri command (#50)
Browse files Browse the repository at this point in the history
*Add set-uri command

The set-uri command will accept an argument which will be then be set as the default URI value locally.
Passing no arguments will prompt the user for input, but will also display a currently stored URI.  Hitting enter
without an input will use that stored URI.  If no URI is stored then the prompt will refresh.

*Updates addressing comments:

- Add a docstring for the new command
- Make the set-uri command call a user prompt action if the command is
run without an argument.
- Reworked the set-uri with updated docstring and with a leaner output
- Added the set-uri to the Readme.
  • Loading branch information
James Berkheimer authored Jun 14, 2023
1 parent 5f77fba commit 946b1d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ configurations and listing the commands available.
configured shell when the launched application exits. Returning you to your existing
shell without modification. Useful for quickly testing changes to a configuration
requiring a running an application.
5. `hab set-uri`: A command that allows the user to set a default URI. This default will be used with the dash `"-"` flag, which allows the user to quickly recall the saved URI. A argument can be passed to directly set the default. Alternatively, it can be run with no argument which will provide a prompt for the user to enter a URI. This method will display any currently saved URI for reference.

Examples:

Expand Down
23 changes: 23 additions & 0 deletions hab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,29 @@ def _cli(
logging.basicConfig(level=level)


# set uri command
@_cli.command()
@click.argument("uri", required=False)
@click.pass_obj
def set_uri(settings, uri):
'''Allows for saving a local URI default by passing
a URI argument. If no argument is passed uri-set
will prompt you to enter and argument.'''
settings.log_context(uri)
current_uri = settings.resolver.user_prefs().uri
if uri is None:
uri = click.prompt(
"Please enter a URI value"
f"[{Fore.LIGHTBLUE_EX}{current_uri}{Fore.RESET}]",
default=current_uri,
show_default=False,
type=str,
err=True,
)
click.echo(f"\nSetting default URI to: {Fore.LIGHTBLUE_EX}{uri}{Fore.RESET}\n")
settings.resolver.user_prefs().uri = uri


# env command
@_cli.command(cls=UriHelpClass)
@click.argument("uri", cls=UriArgument)
Expand Down

0 comments on commit 946b1d7

Please sign in to comment.