Skip to content

Commit

Permalink
Merge pull request #2 from AlexanderARodin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
AlexanderARodin authored Feb 5, 2024
2 parents 7cc3556 + f93c266 commit 7f9eea5
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 78 deletions.
232 changes: 232 additions & 0 deletions Cargo.lock

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

77 changes: 70 additions & 7 deletions src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,80 @@
use std::error::Error;
use toml::{ Table, Value };

use crate::prelude::*;
use crate::utils;


// // // // // // // //
// backend
// // // // // // // //
use super::CallItem;


pub fn push_value( list: &mut Vec<CallItem>, value: &Value ) -> Result< (), Box<dyn Error> > {
pub fn push_sub_script( list: &mut Vec<CallItem>, src_tbl: &toml::Table, path: &str ) -> ResultOf< () > {
match utils::get_value_by_path( src_tbl, path) {
Some(toml::Value::Array(val_arr)) => {
for val in val_arr {
push_script_value(list, src_tbl, val)?;
}
return Ok(());
},
None => {
let msg = format!( "<from_toml_table>: invalid path to workflow <{path}>" );
return Err(Box::from( msg ));
},
_ => {
let msg = format!( "<from_toml_table>: workflow must be an array" );
return Err(Box::from( msg ));
},
}
}

fn push_script_value( list: &mut Vec<CallItem>, src_tbl: &toml::Table, value: &Value) -> ResultOf< () > {
match value {
Value::String(s) => {
return push_simple_item( list, s );
},
Value::Array(arr) => {
return push_subscripts( list, src_tbl, arr );
},
_ => {
let msg = format!( "<push_script_value>: unsupported value <{value}>" );
return Err(Box::from( msg ));
},
}
}

fn push_subscripts( list: &mut Vec<CallItem>, src_tbl: &toml::Table, arr: &Vec<Value> ) -> ResultOf< () > {
for val in arr {
push_subscript_link( list, src_tbl, val )?;
}
Ok(())
}

fn push_subscript_link( list: &mut Vec<CallItem>, src_tbl: &toml::Table, link: &Value ) -> ResultOf< () > {
match link {
Value::String(path) => {
return push_sub_script(list, src_tbl, path);
},
_ => {
let msg = format!( "<push_subscript_link>: unsupported link <{link}>" );
return Err(Box::from( msg ));
},
}
}









pub fn push_value( list: &mut Vec<CallItem>, value: &Value ) -> ResultOf< () > {
match value {
Value::String(cmd) => {
push_simple_command( list, cmd )?;
push_simple_item( list, cmd )?;
},
Value::Array(arr) => {
push_command_array( list, arr )?;
Expand All @@ -27,22 +90,22 @@ pub fn push_value( list: &mut Vec<CallItem>, value: &Value ) -> Result< (), Box<
}

// // // // // // // //
fn push_command_array( list: &mut Vec<CallItem>, arr: &Vec<Value> ) -> Result< (), Box<dyn Error> > {
fn push_command_array( list: &mut Vec<CallItem>, arr: &Vec<Value> ) -> ResultOf< () > {
for value in arr {
push_value( list, value )?;
}
Ok(())
}

fn push_command_table( list: &mut Vec<CallItem>, tbl: &Table ) -> Result< (), Box<dyn Error> > {
fn push_command_table( list: &mut Vec<CallItem>, tbl: &Table ) -> ResultOf< () > {
for (key, value) in tbl {
push_key_value( list, key, value )?;
}
Ok(())
}

// // // // // // // //
fn push_key_value( list: &mut Vec<CallItem>, key: &str, value: &Value ) -> Result< (), Box<dyn Error> > {
fn push_key_value( list: &mut Vec<CallItem>, key: &str, value: &Value ) -> ResultOf< () > {
match value {
Value::String(param) => {
list.push(
Expand All @@ -55,7 +118,7 @@ fn push_key_value( list: &mut Vec<CallItem>, key: &str, value: &Value ) -> Resul
}
Ok(())
}
fn push_simple_command( list: &mut Vec<CallItem>, cmd: &str ) -> Result< (), Box<dyn Error> > {
fn push_simple_item( list: &mut Vec<CallItem>, cmd: &str ) -> ResultOf< () > {
list.push(
CallItem::Simple(cmd.to_string())
);
Expand Down
Loading

0 comments on commit 7f9eea5

Please sign in to comment.