Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .config/jp/tools/src/fs/create_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ pub(crate) async fn fs_create_file(
Some(true) => {}
Some(false) => return error("Path points to existing file"),
None => {
return Ok(Outcome::NeedsInput {
question: Question::boolean(
"overwrite_file",
format!("File '{path}' exists. Overwrite?"),
)
.with_default(Value::Bool(false)),
});
let question = Question::boolean(
"overwrite_file",
format!("File '{path}' exists. Overwrite?"),
)?
.with_default(Value::Bool(false));
return Ok(Outcome::NeedsInput { question });
}
},
None => {}
Expand Down
13 changes: 6 additions & 7 deletions .config/jp/tools/src/fs/delete_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ pub(crate) async fn fs_delete_file(
return error("File has uncommitted changes. Please stage or discard first.");
}
None => {
return Ok(Outcome::NeedsInput {
question: Question::boolean(
"delete_dirty_file",
format!("File '{path}' has uncommitted changes. Delete anyway?"),
)
.with_default(Value::Bool(false)),
});
let question = Question::boolean(
"delete_dirty_file",
format!("File '{path}' has uncommitted changes. Delete anyway?"),
)?
.with_default(Value::Bool(false));
return Ok(Outcome::NeedsInput { question });
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions .config/jp/tools/src/fs/modify_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,15 @@ fn guard_broad_replacement(
Some(true) => None,
Some(false) => Some(fail(reject_message)),
None => {
let mut q =
Question::boolean("broad_replacement", text).with_default(Value::Bool(false));
let question = match Question::boolean("broad_replacement", text) {
Ok(q) => q,
Err(e) => return Some(Err(e.into())),
};
let mut question = question.with_default(Value::Bool(false));
if let Some(p) = pre_amble {
q = q.with_preamble(p);
question = question.with_preamble(p);
}
Some(Ok(Outcome::NeedsInput { question: q }))
Some(Ok(Outcome::NeedsInput { question }))
}
}
}
Expand Down Expand Up @@ -751,12 +754,11 @@ fn apply_changes<R: ProcessRunner>(
return Err("File has uncommitted changes. Change discarded.".into());
}
None => {
return Ok(Outcome::NeedsInput {
question: Question::boolean(
"modify_dirty_file",
format!("File '{path}' has uncommitted changes. Modify anyway?"),
),
});
let question = Question::boolean(
"modify_dirty_file",
format!("File '{path}' has uncommitted changes. Modify anyway?"),
)?;
return Ok(Outcome::NeedsInput { question });
}
}
}
Expand Down Expand Up @@ -800,14 +802,13 @@ fn apply_changes<R: ProcessRunner>(
);
}
None => {
return Ok(Outcome::NeedsInput {
question: Question::boolean(
"apply_changes",
"Do you want to apply the patch shown above?",
)
.with_preamble(patch)
.with_default(Value::Bool(true)),
});
let question = Question::boolean(
"apply_changes",
"Do you want to apply the patch shown above?",
)?
.with_preamble(patch)
.with_default(Value::Bool(true));
return Ok(Outcome::NeedsInput { question });
}
}

Expand Down
33 changes: 19 additions & 14 deletions .config/jp/tools/src/fs/move_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn fs_move_file_impl<R: ProcessRunner>(
// so. Lumping symlinks in here is consistent with the source
// side, where the link entry itself is what gets renamed.
Some(_) => {
if let Some(outcome) = confirm_overwrite_file(answers, target) {
if let Some(outcome) = confirm_overwrite_file(answers, target)? {
return Ok(outcome);
}
}
Expand Down Expand Up @@ -221,19 +221,23 @@ fn classify_source(
Ok(Some(result))
}

fn confirm_overwrite_file(answers: &Map<String, Value>, target: &str) -> Option<Outcome> {
fn confirm_overwrite_file(
answers: &Map<String, Value>,
target: &str,
) -> Result<Option<Outcome>, Error> {
match answers.get("overwrite_file").and_then(Value::as_bool) {
Some(true) => None,
Some(false) => Some(error_outcome(format!(
Some(true) => Ok(None),
Some(false) => Ok(Some(error_outcome(format!(
"Destination '{target}' already exists."
))),
None => Some(Outcome::NeedsInput {
question: Question::boolean(
)))),
None => {
let question = Question::boolean(
"overwrite_file",
format!("Destination '{target}' exists. Overwrite?"),
)
.with_default(Value::Bool(false)),
}),
)?
.with_default(Value::Bool(false));
Ok(Some(Outcome::NeedsInput { question }))
}
}
}

Expand Down Expand Up @@ -278,10 +282,11 @@ fn confirm_dirty_source<R: ProcessRunner>(
Some(false) => Ok(Some(error_outcome(format!(
"'{source}' has uncommitted changes; please stage or discard first."
)))),
None => Ok(Some(Outcome::NeedsInput {
question: Question::boolean("move_dirty_source", prompt)
.with_default(Value::Bool(false)),
})),
None => {
let question =
Question::boolean("move_dirty_source", prompt)?.with_default(Value::Bool(false));
Ok(Some(Outcome::NeedsInput { question }))
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions .config/jp/tools/src/git/stage_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ fn git_stage_patch_impl<R: ProcessRunner>(
return Ok("Changes not staged.".into());
}
None => {
return Ok(Outcome::NeedsInput {
question: Question::boolean(
"stage_changes",
"Do you want to stage the patch shown above?",
)
.with_preamble(combined)
.with_default(Value::Bool(true)),
});
let question = Question::boolean(
"stage_changes",
"Do you want to stage the patch shown above?",
)?
.with_preamble(combined)
.with_default(Value::Bool(true));
return Ok(Outcome::NeedsInput { question });
}
}

Expand Down
Loading
Loading