Validate name in llama stack build (#128)

The first time I ran `llama stack build`, I quickly hit enter at the
first prompt asking for a name, assuming it would use the default
given in the help text. This caused a failure later on that wasn't
very obvious. I was using the `docker` format and a blank name caused
an invalid tag format that failed the image build.

This change adds validation for the `name` parameter to ensure it's
not empty before proceeding.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
This commit is contained in:
Russell Bryant 2024-09-27 16:30:55 -04:00 committed by GitHub
parent 53070e34a3
commit fb9e6371ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -199,7 +199,11 @@ class StackBuild(Subcommand):
if not args.config and not args.template:
if not args.name:
name = prompt(
"> Enter a name for your Llama Stack (e.g. my-local-stack): "
"> Enter a name for your Llama Stack (e.g. my-local-stack): ",
validator=Validator.from_callable(
lambda x: len(x) > 0,
error_message="Name cannot be empty, please enter a name",
),
)
else:
name = args.name