Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spin new: match unrecognised template as tag #1530

Merged
merged 1 commit into from
May 22, 2023

Conversation

itowlson
Copy link
Contributor

This, prompted by #1525, makes spin new/add more forgiving of users unsure of the exact template name. If the template is not recognised, it tries to recover by searching for it as a tag:

ivan@hecate:~/testing$ spin new rust tplmadness
Pick a template to start your application with:
> http-rust (HTTP request handler using Rust)
  redis-rust (Redis message handler using Rust)

ivan@hecate:~/testing$ spin new http tplmadness
Pick a template to start your application with:
> http-c (HTTP request handler using C and the Zig toolchain)
  http-empty (HTTP application with no components)
  http-go (HTTP request handler using (Tiny)Go)
  http-grain (HTTP request handler using Grain)
  http-php (HTTP request handler using PHP)
  http-py (HTTP request handler using Python)
  http-rust (HTTP request handler using Rust)
  http-swift (HTTP request handler using SwiftWasm)
  http-zig (HTTP request handler using Zig)
  static-fileserver (Serves static files from an asset directory)

ivan@hecate:~/testing$ spin new biscuits tplmadness
Error: No templates matched 'biscuits'

This could be made even more forgiving by using a name match too:

ivan@hecate:~/testing$ spin new r tplmadness
Error: No templates matched 'r'  # What if this listed all templates containing 'r', or with 'r' in a start-of-word position?

And if we wanted to meet the original request in #1525 we could recognise a special value such as . as matching anything, but then maybe we get into the "I can never remember the special value" problem...

Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable to me!

if tags.len() == 1 {
bail!("No templates matched '{}'", tags[0]);
} else {
bail!("No templates matched all of '{}'", tags.join(" and "));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if there are many tags wouldn't this output look strange (e.g., "foo and bar and baz and qux")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multi-tag case can only happen when the user explicitly supplies tags using the --tag flag. So I can condense this down to No templates matched all tags without listing them. Thanks!

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson itowlson force-pushed the template-new-autotag-from-id branch from ed5639a to 39e13fc Compare May 22, 2023 19:34
@itowlson itowlson merged commit 75d9414 into fermyon:main May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants