Skip to content

Commit

Permalink
Fix edits from path test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Jan 23, 2024
1 parent b2f8f35 commit dc17dfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions crates/cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ impl Cli {

fn edit(input_args: InputArgs) -> anyhow::Result<()> {
let explicit_file_path = input_args.file.as_deref();
if explicit_file_path.is_some_and(|file_arg| !file_arg.exists()) {
// TODO: return error suggesting to run `rops encrypt --in-place FILE`
todo!()
}

return match Self::get_format(explicit_file_path, input_args.format)? {
Format::Yaml => edit_encrypted_file::<YamlFileFormat>(explicit_file_path),
Expand Down Expand Up @@ -151,6 +147,7 @@ impl Cli {
}
}

/// Returns Ok(None) if operation was cancelled.
fn edit_temp_file<F: FileFormat>(temp_file_path: &Path) -> anyhow::Result<Option<RopsFileFormatMap<DecryptedMap, F>>> {
let (editor_command, args) = select_editor()?;
let mut command = Command::new(editor_command);
Expand Down Expand Up @@ -203,6 +200,7 @@ impl Cli {
bail!(RopsCliError::MultipleInputs)
}
drop(stdin_guard);

std::fs::read_to_string(plaintext_path)?
}
None => {
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ fn edits_from_file() {

let mut cmd = Command::package_command().edit_age();
cmd.arg(temp_file.path());
cmd.run_tty();

let encrypted_content = std::fs::read_to_string(temp_file.path()).unwrap();
pretty_assertions::assert_eq!(EDIT_CONTENT, decrypt_str::<AgeIntegration>(&encrypted_content).to_string())
pretty_assertions::assert_eq!(EDIT_CONTENT, decrypt_str::<AgeIntegration>(&encrypted_content).map().to_string())
}

fn assert_encrypted<I: IntegrationTestUtils>(encrypted_output: Output, expected_plaintext: &str) {
Expand Down Expand Up @@ -159,9 +160,8 @@ impl EditCommand for Command {
fn edit_age(mut self) -> Self {
std::env::set_var(
"EDITOR",
format!("{} \"{}\"", path_to_mock_editor().to_str().expect("valid unicode"), EDIT_CONTENT),
format!("{} '{}'", path_to_mock_editor().to_str().expect("valid unicode"), EDIT_CONTENT),
);

AgeIntegration::set_mock_private_key_env_var();

self.arg("edit");
Expand Down

0 comments on commit dc17dfc

Please sign in to comment.