diff --git a/README.md b/README.md index a7d0d5e..afc9607 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/hab/cli.py b/hab/cli.py index a786883..c6abc61 100644 --- a/hab/cli.py +++ b/hab/cli.py @@ -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)