I'm writing a small CLI app to set up my development environment based on a Jira ticket, currently I'm trying to open VS Code but I get a command not found error even though I can open VS Code from withing my terminal.
// jira.rs
use std::fmt;
pub struct JiraTicket {
pub key: String,
pub number: u32,
}
impl JiraTicket {
pub fn new(key: String, number: u32) -> JiraTicket {
JiraTicket { key, number }
}
}
impl fmt::Display for JiraTicket {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}-{}", self.key, self.number)
}
}
// command.rs
pub fn open_vscode(ticket: Option<&JiraTicket>) {
let path = match ticket {
Some(path) => path.to_string(),
None => ".".to_string(),
};
let vscode_command = Command::new("code")
.arg(path)
.status()
.expect("An error ocurred while opening vs code");
if vscode_command.success() {
println!("{}", "Opened VSCode".green());
} else {
println!("{}", "Failed to open VSCode".red());
}
}
I already looked at: