spin icon indicating copy to clipboard operation
spin copied to clipboard

spin new: flag to accept defaults where available

Open michelleN opened this issue 2 years ago • 8 comments

At the moment, spin new prompts for fields like description. If the fields it prompts for are not required by the manifest file, it'd be nice to disable the prompt and leave those optional fields empty. I think this will give us a more streamlined spin new experience.

michelleN avatar Jun 17 '22 16:06 michelleN

Hi, can I pick this up? Can you please point me to the files I would need to look at?

deepto98 avatar Jun 19 '22 14:06 deepto98

new.rs holds the top level logic for the spin new command. --> https://github.com/fermyon/spin/blob/main/src/commands/new.rs

We'll also need to confirm which fields can be omitted. @fibonacci1729 @itowlson - ya'll have any thoughts on this issue?

michelleN avatar Jun 20 '22 13:06 michelleN

Everything in HTTP has sensible defaults. Not sure about Redis. The question is what we want users to think about and what not...

If the request is simply to remove the prompt, you shouldn't need to change new to make a change like this. Each template defines its own set of questions - you should be able to delete the questions out of the template manifest (and replace the substitutions in the content directory with the desired fixed values, or remove the entries).

If the request is to allow an empty response to the prompt, that would require changes in the template subsystem, crates/template, specifically run.rs (and probably in the template schema, template.rs). Again, shouldn't need anything in new itself.

itowlson avatar Jun 20 '22 19:06 itowlson

The current experience is

$ spin new http-rust hello-fermyon
Project description: 

I'd like to be able to accept defaults and not have to go through the prompt with a flag:

$ spin new http-rust hello-fermyon --accept-defaults

michelleN avatar Jun 21 '22 02:06 michelleN

@michelleN Oh! Thanks for clarifying, sorry for being slow.

@deepto98 Okay, I think this will need work in a couple of places:

  1. If the flag is present, populate the parameter values map from the template defaults. Values passed on the command line or via the values file should still override those defaults (new already has a merge_values function that will help with this). Template has a parameters() method which is pub(crate) but is safe to make pub.
  2. Set the description default to empty string in the four existing templates.
  3. Allow empty strings for string parameters, at least as defaults. (Ideally we should make description optional, but that will need logic that we haven't implemented yet.) This may Just Work - I think the non-empty check is in the UI library not in the constraint validation. If not, you're probably looking at the TemplateParameter::validate_value function in template.rs.

Thanks for pitching in here, hope this is enough pointers.

itowlson avatar Jun 21 '22 02:06 itowlson

@deepto98 Just wanted to check in with you if you were still working on this issue.

karthik2804 avatar Aug 04 '22 10:08 karthik2804

@karthik2804 — I think it would be ok if you wanted to have a look at this issue. Thanks!

radu-matei avatar Aug 16 '22 03:08 radu-matei

@radu-matei I will pick this one up.

karthik2804 avatar Aug 17 '22 03:08 karthik2804