Skip to content

Commit 1ebec84

Browse files
authored
Merge pull request #6 from chenrui333/tfocus-opentofu
feat: add opentofu support and msrv
2 parents c271b8d + b92ce10 commit 1ebec84

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ repository = "https://github.com/nwiizo/tfocus"
88
documentation = "https://github.com/nwiizo/tfocus"
99
homepage = "https://github.com/nwiizo/tfocus"
1010
authors = ["[email protected]"]
11-
keywords = ["terraform", "cli", "workspace"]
11+
keywords = ["terraform", "opentofu", "cli", "workspace"]
1212
categories = ["command-line-utilities"]
13+
rust-version = "1.78.0"
1314

1415

1516
[dependencies]

src/executor.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use log::{debug, error};
2+
use std::env;
23
use std::path::Path;
34
use std::process::Command;
45
use std::sync::atomic::{AtomicBool, Ordering};
@@ -51,6 +52,7 @@ fn setup_signal_handler() -> Result<Arc<AtomicBool>> {
5152
}
5253
#[cfg(windows)]
5354
{
55+
// Additional Windows termination logic here if needed.
5456
use windows::Win32::Foundation::HANDLE;
5557
use windows::Win32::System::Threading::{OpenProcess, TerminateProcess};
5658
}
@@ -122,7 +124,10 @@ fn execute_terraform_command(
122124
working_dir: &Path,
123125
running: Arc<AtomicBool>,
124126
) -> Result<bool> {
125-
let mut command = Command::new("terraform");
127+
// read `TERRAFORM_BINARY_NAME` env, fallback to "terraform"
128+
let terraform_binary =
129+
env::var("TERRAFORM_BINARY_NAME").unwrap_or_else(|_| "terraform".to_string());
130+
let mut command = Command::new(&terraform_binary);
126131
command.arg(operation.to_string()).current_dir(working_dir);
127132

128133
for target in target_options {
@@ -134,15 +139,16 @@ fn execute_terraform_command(
134139
}
135140

136141
let command_str = format!(
137-
"terraform {} {}{}",
142+
"{} {} {}",
143+
terraform_binary,
138144
operation,
139145
target_options.join(" "),
140-
if matches!(operation, Operation::Apply) {
141-
" -auto-approve"
142-
} else {
143-
""
144-
}
145146
);
147+
let command_str = if matches!(operation, Operation::Apply) {
148+
format!("{} -auto-approve", command_str)
149+
} else {
150+
command_str
151+
};
146152

147153
Display::print_command(&command_str);
148154
debug!(

0 commit comments

Comments
 (0)