updated with error handling
This commit is contained in:
parent
275435daf5
commit
f0488cded8
@ -35,7 +35,13 @@ impl CuddleAction {
|
|||||||
for (k, v) in args {
|
for (k, v) in args {
|
||||||
let var = match v {
|
let var = match v {
|
||||||
CuddleShellScriptArg::Env(e) => {
|
CuddleShellScriptArg::Env(e) => {
|
||||||
let env_var = env::var(e.key.clone())?;
|
let env_var = match env::var(e.key.clone()) {
|
||||||
|
Ok(var) => var,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("env_variable not found: {}", k);
|
||||||
|
return Err(anyhow::anyhow!(e));
|
||||||
|
}
|
||||||
|
};
|
||||||
CuddleVariable::new(k.clone(), env_var)
|
CuddleVariable::new(k.clone(), env_var)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -49,6 +55,8 @@ impl CuddleAction {
|
|||||||
let mut vars = variables.clone();
|
let mut vars = variables.clone();
|
||||||
vars.append(&mut arg_variables);
|
vars.append(&mut arg_variables);
|
||||||
|
|
||||||
|
log::trace!("preparing to run action");
|
||||||
|
|
||||||
match actions::shell::ShellAction::new(
|
match actions::shell::ShellAction::new(
|
||||||
self.name.clone(),
|
self.name.clone(),
|
||||||
format!(
|
format!(
|
||||||
@ -61,7 +69,10 @@ impl CuddleAction {
|
|||||||
)
|
)
|
||||||
.execute(vars)
|
.execute(vars)
|
||||||
{
|
{
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => {
|
||||||
|
log::trace!("finished running action");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("{}", e);
|
log::error!("{}", e);
|
||||||
Err(e)
|
Err(e)
|
||||||
@ -274,19 +285,19 @@ impl<'a> CuddleCli<'a> {
|
|||||||
|
|
||||||
match exe_submatch.subcommand() {
|
match exe_submatch.subcommand() {
|
||||||
Some((name, _action_matches)) => {
|
Some((name, _action_matches)) => {
|
||||||
log::trace!(action=name; "running action");
|
log::trace!(action=name; "running action; name={}", name);
|
||||||
match self.scripts.iter().find(|ele| ele.name == name) {
|
match self.scripts.iter().find(|ele| ele.name == name) {
|
||||||
Some(script) => {
|
Some(script) => {
|
||||||
script.clone().execute(self.variables.clone());
|
script.clone().execute(self.variables.clone())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => (Err(anyhow!("could not find a match"))),
|
_ => Err(anyhow!("could not find a match")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (Err(anyhow!("could not find a match"))),
|
_ => Err(anyhow!("could not find a match")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (Err(anyhow!("could not find a match"))),
|
_ => Err(anyhow!("could not find a match")),
|
||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
|
@ -35,7 +35,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
fn init_logging() -> anyhow::Result<()> {
|
fn init_logging() -> anyhow::Result<()> {
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.pretty()
|
.pretty()
|
||||||
.with_max_level(Level::INFO)
|
.with_max_level(Level::TRACE)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user