feat: echo mode

This commit is contained in:
iff 2025-03-13 21:33:13 +01:00
parent ec9609f470
commit 1b018bc763
4 changed files with 20 additions and 1 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Nushell: Added alias support
- Also allows arbitrary shell to provide support
- `echo` mode: Only print suggestion
### Fixed

View file

@ -54,6 +54,7 @@ fn main() -> Result<(), std::io::Error> {
use shell::Mode::*;
match data.mode {
Suggestion => modes::suggestion(&mut data),
Echo => modes::echo(&mut data),
Cnf => modes::cnf(&mut data),
}

View file

@ -54,6 +54,18 @@ pub fn suggestion(data: &mut Data) {
);
}
pub fn echo(data: &mut Data) {
let shell = data.shell.clone();
suggest_candidates(data);
if data.candidates.is_empty() {
eprintln!("No suggestions found")
};
for candidate in &mut data.candidates {
shell::shell_syntax(&shell, candidate);
println!("{} <_PR_BR>", candidate);
}
}
pub fn cnf(data: &mut Data) {
let shell = data.shell.clone();
let mut split_command = data.split.clone();

View file

@ -17,6 +17,7 @@ pub const PRIVILEGE_LIST: [&str; 2] = ["sudo", "doas"];
#[derive(PartialEq)]
pub enum Mode {
Suggestion,
Echo,
Cnf,
}
pub struct Init {
@ -382,7 +383,11 @@ pub fn run_mode() -> Mode {
Ok(mode) => match mode.as_str() {
"suggestion" => Mode::Suggestion,
"cnf" => Mode::Cnf,
_ => Mode::Suggestion,
"echo" => Mode::Echo,
_ => {
eprintln!("Invalid mode: {}", mode);
exit(1);
}
},
Err(_) => Mode::Suggestion,
}