Skip to content
New issue

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

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

Already on GitHub? # to your account

Support v1 syntax for spin new and spin add #1953

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

itowlson
Copy link
Contributor

By popular demand, we changed the spin new/add syntax in Spin 2 to spin new [NAME] [-t TEMPLATE].

The trouble is we have a lot of content out there, such as videos and blogs, which walks people through using the v1 syntax, and would be extremely expensive to remake.

This PR introduces an ugly hack by which if a user uses the old syntax, spin new TEMPLATE NAME, then we spot that there are two positional args and interpret them accordingly. This does leave us in the ugly position that in spin new foo foo is the app name and in spin new foo bar foo is the template name but I don't know how to resolve that. It is going to be a vexing experience for people who forget the -t because the error will be not guide them to "missing flag".

The behaviour now is:

# V1 syntax, creates a Rust app named tnpos
ivan@hecate:~/testing/tpltest$ spin new http-rust tnpos
Description:
HTTP path: /...

# Treated as V2 syntax, prompts for template, warns in case they meant V1 syntax
ivan@hecate:~/testing/tpltest$ spin new http-rust
This will create an app called http-rust. If you meant to use the http-rust template, write '-t http-rust'.

# Treated as V2 syntax, prompts for template
ivan@hecate:~/testing/tpltest$ spin new myapp

# V2 syntax, prompts for name
ivan@hecate:~/testing/tpltest$ spin new -t http-rust
Enter a name for your new application: fie
Description:
HTTP path: /...

# V2 syntax, creates Rust app called ntarg
ivan@hecate:~/testing/tpltest$ spin new ntarg -t http-rust
Description:
HTTP path: /...

# Treated as V1 syntax because two positional parameters, but fails
ivan@hecate:~/testing/tpltest$ spin new myapp http-rust
Error: No templates matched 'myapp'

# Bad syntax, berates user
ivan@hecate:~/testing/tpltest$ spin new myapp http-rust -t http-rust
Error: Cannot supply both positional and named template id

Copy link
Member

@mikkelhegn mikkelhegn left a comment

Choose a reason for hiding this comment

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

LGTM

@rylev
Copy link
Collaborator

rylev commented Oct 26, 2023

Can we add some warnings so that people are educated about the new syntax? Preferably this will allow us to eventually remove this hack.

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson itowlson force-pushed the templates-support-v1-syntax branch from 7b23f57 to 36d77d0 Compare October 26, 2023 18:55
@itowlson
Copy link
Contributor Author

@rylev added

$ spin new http-rust biscuits
Using Spin 1 command syntax. The recommended syntax in Spin 2 is 'spin new biscuits -t http-rust'

@itowlson itowlson enabled auto-merge October 26, 2023 19:14
@itowlson itowlson merged commit b45feb8 into fermyon:main Oct 26, 2023
9 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants