Skip to content

Commit

Permalink
support "-zsh" as zsh (#21)
Browse files Browse the repository at this point in the history
fixes #20

Separating our shell_types to it's own module to improve readability
of bloated main function.

Modifying test structure to match more modern patterns (tests directory
matching src structure)
  • Loading branch information
toumorokoshi authored Jan 14, 2022
1 parent 0bacb82 commit 90b3ba9
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 197 deletions.
128 changes: 98 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ termion = "*"


[dev-dependencies]
rstest = "0.12.0"
36 changes: 10 additions & 26 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::super::shell_type::{get_shell_type, ShellType};
use std::{
env,
iter::{Iterator, Peekable},
path::Path,
slice::Iter,
};

Expand Down Expand Up @@ -195,32 +195,13 @@ pub fn init(tome_executable: &str, mut args: Peekable<Iter<String>>) -> Result<S
} else {
return Err(format!(
init_help_body!(),
"function name required for init invocation"
"shell name is required for init invocation"
));
}
}
};
// strip any leading directories. The root should be the shell.
let shell_type = match Path::new(shell_type_or_path).file_stem() {
Some(p) => match p.to_str() {
Some(inner_p) => inner_p,
None => {
return Err(format!(
init_help_body!(),
format!(
"could not convert shell type to string for '{}'",
shell_type_or_path
)
));
}
},
None => {
return Err(format!(
init_help_body!(),
format!("could not find shell type for '{}'", shell_type_or_path)
));
}
};

let shell_type = get_shell_type(shell_type_or_path)?;
// Bootstrapping the sc section requires two parts:
// 1. creating the function in question
// 2. wiring up tab completion for the function.
Expand All @@ -230,18 +211,21 @@ pub fn init(tome_executable: &str, mut args: Peekable<Iter<String>>) -> Result<S
// current environment (such as cd you into a specific)
// directory.
match shell_type {
"fish" => Ok(format!(
ShellType::FISH => Ok(format!(
fish_init_body!(),
tome_executable = tome_executable,
script_root = script_root,
function_name = function_name
)),
"bash" | "zsh" => Ok(format!(
ShellType::BASH | ShellType::ZSH => Ok(format!(
bash_zsh_init_body!(),
tome_executable = tome_executable,
script_root = script_root,
function_name = function_name
)),
_ => Err(format!("Unknown shell {}. Unable to init.", shell_type)),
ShellType::UNKNOWN => Err(format!(
"could not determine shell from {}. Unable to init.",
shell_type_or_path
)),
}
}
2 changes: 0 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod help;
mod init;
mod script;
#[cfg(test)]
mod tests;
pub use self::help::help;
pub use self::init::init;
pub use self::script::Script;
Loading

0 comments on commit 90b3ba9

Please sign in to comment.