MCPcopy Index your code
hub / github.com/cargo-lambda/cargo-lambda / new_project

Function new_project

crates/cargo-lambda-new/src/lib.rs:135–192  ·  view source on GitHub ↗
(
    name: &str,
    path: T,
    config: &mut Config,
    replace: bool,
)

Source from the content-addressed store, hash-verified

133
134#[tracing::instrument(target = "cargo_lambda")]
135async fn new_project<T: AsRef<Path> + Debug>(
136 name: &str,
137 path: T,
138 config: &mut Config,
139 replace: bool,
140) -> Result<()> {
141 tracing::trace!(name, ?path, ?config, "creating new project");
142
143 validate_name(name)?;
144 if let Some(name) = &config.bin_name {
145 validate_name(name)?;
146 }
147
148 let template = get_template(config).await?;
149 template.cleanup();
150
151 let template_config = template::config::parse_template_config(template.config_path())?;
152 let ignore_default_prompts = template_config.disable_default_prompts || config.no_interactive;
153
154 if config.extension {
155 config.extension_options.validate_options()?;
156 } else {
157 match config
158 .function_options
159 .validate_options(ignore_default_prompts)
160 {
161 Err(CreateError::UnexpectedInput(err)) if is_user_cancellation_error(&err) => {
162 return Ok(());
163 }
164 Err(err) => return Err(err.into()),
165 Ok(()) => {}
166 }
167 }
168
169 let globals = build_template_variables(config, &template_config, name)?;
170 let render_files = build_render_files(config, &template_config);
171 let ignore_files = build_ignore_files(config, &template_config);
172
173 create_project(
174 &path,
175 &template.final_path(),
176 &template_config,
177 &globals,
178 &render_files,
179 &ignore_files,
180 replace,
181 )
182 .await?;
183 if config.open {
184 let path_ref = path.as_ref();
185 let path_str = path_ref
186 .to_str()
187 .ok_or_else(|| CreateError::NotADirectoryPath(path_ref.to_path_buf()))?;
188 open_code_editor(path_str).await
189 } else {
190 Ok(())
191 }
192}

Callers 1

runMethod · 0.85

Calls 13

validate_nameFunction · 0.85
get_templateFunction · 0.85
parse_template_configFunction · 0.85
build_template_variablesFunction · 0.85
build_render_filesFunction · 0.85
build_ignore_filesFunction · 0.85
create_projectFunction · 0.85
open_code_editorFunction · 0.85
cleanupMethod · 0.80
config_pathMethod · 0.80
final_pathMethod · 0.80

Tested by

no test coverage detected