Skip to content

Commit

Permalink
Ensure the fields vec is not empty on change
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 22, 2024
1 parent 212261a commit ee5c288
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/scaffold/entry_type/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ pub fn choose_fields(
loop {
let action = Select::with_theme(&ColorfulTheme::default())
.with_prompt("What would you like to do?")
.items(&["Modify Field", "Add Field", "Remove Field", "Done"])
.items(&["Change Field", "Add Field", "Remove Field", "Done"])
.interact()?;

match action {
0 => {
// Modify field
let field_to_modify = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select field to modify")
.items(
&fields
.iter()
.map(|f| format!("{}: {}", f.field_name, f.field_type).italic())
.collect::<Vec<_>>(),
)
.interact()?;
// Change field
if !fields.is_empty() {
let field_to_change = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select field to change")
.items(
&fields
.iter()
.map(|f| format!("{}: {}", f.field_name, f.field_type).italic())
.collect::<Vec<_>>(),
)
.interact()?;

let new_field = choose_field(
entry_type_name,
zome_file_tree,
field_types_templates,
no_ui,
Some(&fields[field_to_modify].field_name),
)?;
fields[field_to_modify] = new_field;
let new_field = choose_field(
entry_type_name,
zome_file_tree,
field_types_templates,
no_ui,
Some(&fields[field_to_change].field_name),
)?;
fields[field_to_change] = new_field;
} else {
println!("{}", "No fields left to change".yellow())
}
}
1 => {
// Add field
Expand Down

0 comments on commit ee5c288

Please sign in to comment.