Function wasm_deploy::file::get_shell_completion_dir
source · pub fn get_shell_completion_dir() -> Result<Option<PathBuf>, DeployError>Examples found in repository?
src/commands.rs (line 182)
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
fn generate_completions<C, S>() -> Result<(), DeployError>
where
C: Contract,
S: Subcommand,
{
let shell_completion_dir = match get_shell_completion_dir()? {
Some(shell_completion_dir) => shell_completion_dir,
None => return Ok(()),
};
let string = env::var_os("SHELL").unwrap().into_string().unwrap();
let (_, last_word) = string.rsplit_once('/').unwrap();
let mut cmd = Cli::<C, S>::command();
match last_word {
"zsh" => {
println!("Generating shell completion scripts for zsh");
println!("Run source ~/.zshrc to update your completion scripts");
let generated_file = generate_to(
Zsh,
&mut cmd, // We need to specify what generator to use
"deploy", // We need to specify the bin name manually
BUILD_DIR.as_path(), // We need to specify where to write to
)?;
let source_path = BUILD_DIR.join(generated_file.file_name().unwrap());
let target_path = shell_completion_dir.join(generated_file.file_name().unwrap());
Command::new("rm").arg(target_path.clone()).spawn()?.wait().ok();
if Command::new("cp").arg(source_path).arg(target_path).spawn()?.wait()?.exit_ok().is_err() {
println!("could not find {}", shell_completion_dir.to_str().unwrap());
}
}
"bash" => {
println!("generating shell completion scripts for bash");
let generated_file = generate_to(
Bash,
&mut cmd, // We need to specify what generator to use
"deploy", // We need to specify the bin name manually
BUILD_DIR.as_path(), // We need to specify where to write to
)?;
let source_path = BUILD_DIR.join(generated_file.file_name().unwrap());
let target_path = shell_completion_dir.join(generated_file.file_name().unwrap());
if Command::new("cp").arg(source_path).arg(target_path).spawn()?.wait()?.exit_ok().is_err() {
println!("could not find {}", shell_completion_dir.to_str().unwrap());
}
}
_ => {
return Err(DeployError::UnsupportedShell {});
}
}
Ok(())
}