Commit 10e51001 authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

feat: Make Config::read a little better

parent 0c564f67
Loading
Loading
Loading
Loading
+276 −269
Original line number Diff line number Diff line
@@ -388,43 +388,44 @@ FN:552,EnvironmentValue::set_variable
FN:562,EnvironmentValue::set_variables
FN:569,Extension::from_string
FN:578,Label::dry_run
FN:582,Label::fail
FN:586,Label::found
FN:590,Label::not_found
FN:594,Label::output
FN:598,Label::read
FN:602,Label::rejected
FN:606,Label::run
FN:610,Label::using
FN:616,ModuleUri<'_>::from
FN:626,ModuleUri<'_>::hash
FN:650,ModuleUri<'_>::get_whitelist
FN:653,ModuleUri<'_>::is_allowed
FN:656,ModuleUri<'_>::test
FN:657,ModuleUri<'_>::test::check
FN:674,ModuleUri<'_>::working_directory
FN:686,SemanticVersion::from_string
FN:709,Script::expand_arguments
FN:744,Script::expand_arguments_from
FN:779,Script::from_module
FN:837,Script::from_path
FN:860,Script::from_template
FN:877,Script::get_command
FN:883,Script::get_arguments
FN:894,Script::maybe_create_conda_environment
FN:927,Script::maybe_git_clone
FN:934,Script::python_default
FN:948,Script::run
FN:1019,Script::with_current_dir
FN:1057,Script::with_environment
FN:1062,Script::with_envs
FN:1071,StringTemplate::new
FN:1080,StringTemplate::expand
FN:1087,StringTemplate::get_variable
FN:1117,StringTemplate::is_handlebars
FN:1152,StringTemplate::remove_spaces
FN:1162,add_forward_slash
FNF:54
FN:582,Label::invalid
FN:586,Label::fail
FN:590,Label::found
FN:594,Label::not_found
FN:598,Label::output
FN:602,Label::read
FN:606,Label::rejected
FN:610,Label::run
FN:614,Label::using
FN:620,ModuleUri<'_>::from
FN:630,ModuleUri<'_>::hash
FN:654,ModuleUri<'_>::get_whitelist
FN:657,ModuleUri<'_>::is_allowed
FN:660,ModuleUri<'_>::test
FN:661,ModuleUri<'_>::test::check
FN:678,ModuleUri<'_>::working_directory
FN:690,SemanticVersion::from_string
FN:713,Script::expand_arguments
FN:748,Script::expand_arguments_from
FN:783,Script::from_module
FN:841,Script::from_path
FN:864,Script::from_template
FN:881,Script::get_command
FN:887,Script::get_arguments
FN:898,Script::maybe_create_conda_environment
FN:931,Script::maybe_git_clone
FN:938,Script::python_default
FN:952,Script::run
FN:1023,Script::with_current_dir
FN:1061,Script::with_environment
FN:1066,Script::with_envs
FN:1075,StringTemplate::new
FN:1084,StringTemplate::expand
FN:1091,StringTemplate::get_variable
FN:1121,StringTemplate::is_handlebars
FN:1156,StringTemplate::remove_spaces
FN:1166,add_forward_slash
FNF:55
FNDA:1,Command::test
FNDA:1,Config::read
FNDA:1,Config::read_json
@@ -443,6 +444,7 @@ FNDA:0,EnvironmentValue::set_variable
FNDA:0,EnvironmentValue::set_variables
FNDA:1,Extension::from_string
FNDA:0,Label::dry_run
FNDA:0,Label::invalid
FNDA:0,Label::fail
FNDA:0,Label::found
FNDA:0,Label::not_found
@@ -496,23 +498,25 @@ DA:414,1
DA:415,2
DA:416,2
DA:417,1
DA:419,0
DA:420,0
DA:423,2
DA:424,1
DA:426,0
DA:427,0
DA:418,0
DA:420,2
DA:421,1
DA:422,0
DA:426,2
DA:427,1
DA:429,0
DA:430,0
DA:438,1
DA:439,2
DA:440,2
DA:442,0
DA:443,0
DA:446,2
DA:447,1
DA:448,2
DA:447,2
DA:448,4
DA:449,0
DA:451,3
DA:452,1
DA:451,6
DA:452,2
DA:459,1
DA:460,2
DA:461,1
@@ -600,12 +604,12 @@ DA:588,0
DA:590,0
DA:591,0
DA:592,0
DA:594,1
DA:595,1
DA:596,1
DA:598,0
DA:599,0
DA:600,0
DA:594,0
DA:595,0
DA:596,0
DA:598,1
DA:599,2
DA:600,1
DA:602,0
DA:603,0
DA:604,0
@@ -615,284 +619,287 @@ DA:608,0
DA:610,0
DA:611,0
DA:612,0
DA:616,1
DA:617,1
DA:618,3
DA:619,2
DA:620,2
DA:621,0
DA:623,1
DA:626,1
DA:614,0
DA:615,0
DA:616,0
DA:620,1
DA:621,1
DA:622,3
DA:623,2
DA:624,2
DA:625,0
DA:627,1
DA:628,1
DA:629,1
DA:630,2
DA:631,0
DA:633,4
DA:630,1
DA:631,1
DA:632,1
DA:633,1
DA:634,2
DA:635,0
DA:637,4
DA:638,4
DA:640,4
DA:641,2
DA:643,2
DA:646,0
DA:641,4
DA:642,4
DA:644,4
DA:645,2
DA:647,2
DA:650,0
DA:651,0
DA:653,0
DA:654,0
DA:656,0
DA:655,0
DA:657,0
DA:658,0
DA:660,0
DA:661,0
DA:662,0
DA:663,0
DA:664,0
DA:665,0
DA:666,0
DA:667,0
DA:668,0
DA:669,0
DA:670,0
DA:672,0
DA:674,0
DA:675,0
DA:676,0
DA:677,0
DA:678,0
DA:679,0
DA:680,0
DA:681,0
DA:686,1
DA:687,1
DA:688,3
DA:689,3
DA:690,3
DA:709,1
DA:710,2
DA:713,2
DA:714,1
DA:715,2
DA:716,1
DA:717,1
DA:682,0
DA:684,0
DA:685,0
DA:690,1
DA:691,1
DA:692,3
DA:693,3
DA:694,3
DA:713,1
DA:714,2
DA:717,2
DA:718,1
DA:719,2
DA:723,1
DA:724,1
DA:744,1
DA:745,2
DA:748,2
DA:749,1
DA:750,2
DA:751,2
DA:720,1
DA:721,1
DA:723,2
DA:727,1
DA:728,1
DA:748,1
DA:749,2
DA:752,2
DA:753,1
DA:754,2
DA:756,1
DA:755,2
DA:758,2
DA:762,1
DA:763,1
DA:779,0
DA:781,0
DA:782,0
DA:760,1
DA:762,2
DA:766,1
DA:767,1
DA:783,0
DA:785,0
DA:786,0
DA:787,0
DA:788,0
DA:789,0
DA:790,0
DA:791,0
DA:792,0
DA:793,0
DA:794,0
DA:796,0
DA:797,0
DA:798,0
DA:799,0
DA:800,0
DA:801,0
DA:802,0
DA:803,0
DA:804,0
DA:805,0
DA:807,0
DA:808,0
DA:810,0
DA:811,0
DA:809,0
DA:812,0
DA:814,0
DA:820,0
DA:821,0
DA:837,1
DA:838,2
DA:839,1
DA:841,0
DA:842,0
DA:845,2
DA:846,1
DA:847,1
DA:860,1
DA:861,1
DA:862,3
DA:866,2
DA:868,2
DA:815,0
DA:818,0
DA:824,0
DA:825,0
DA:841,1
DA:842,2
DA:843,1
DA:845,0
DA:846,0
DA:849,2
DA:850,1
DA:851,1
DA:864,1
DA:865,1
DA:866,3
DA:870,2
DA:873,1
DA:872,2
DA:874,2
DA:875,3
DA:877,1
DA:878,1
DA:879,1
DA:880,1
DA:878,2
DA:879,3
DA:881,1
DA:882,1
DA:883,1
DA:884,1
DA:885,3
DA:886,3
DA:887,6
DA:888,2
DA:890,1
DA:894,0
DA:895,0
DA:896,0
DA:897,0
DA:887,1
DA:888,1
DA:889,3
DA:890,3
DA:891,6
DA:892,2
DA:894,1
DA:898,0
DA:899,0
DA:900,0
DA:901,0
DA:902,0
DA:903,0
DA:904,0
DA:905,0
DA:906,0
DA:907,0
DA:908,0
DA:909,0
DA:910,0
DA:911,0
DA:912,0
DA:913,0
DA:914,0
DA:915,0
DA:916,0
DA:918,0
DA:919,0
DA:922,0
DA:923,0
DA:927,1
DA:928,2
DA:929,2
DA:930,2
DA:931,3
DA:932,1
DA:934,0
DA:935,0
DA:936,0
DA:944,0
DA:948,1
DA:949,1
DA:950,1
DA:951,2
DA:952,2
DA:953,3
DA:926,0
DA:927,0
DA:931,1
DA:932,2
DA:933,2
DA:934,2
DA:935,3
DA:936,1
DA:938,0
DA:939,0
DA:940,0
DA:948,0
DA:952,1
DA:953,1
DA:954,1
DA:955,9
DA:955,2
DA:956,2
DA:957,1
DA:957,3
DA:958,1
DA:959,1
DA:960,1
DA:965,2
DA:966,3
DA:968,0
DA:969,0
DA:972,3
DA:973,3
DA:974,4
DA:975,9
DA:976,6
DA:979,6
DA:980,3
DA:982,0
DA:983,0
DA:986,3
DA:987,3
DA:988,6
DA:989,0
DA:990,0
DA:993,6
DA:994,1
DA:995,9
DA:996,3
DA:997,7
DA:998,9
DA:999,3
DA:1001,3
DA:1002,3
DA:1003,2
DA:1006,0
DA:1007,0
DA:1008,0
DA:959,9
DA:960,3
DA:961,1
DA:962,1
DA:963,1
DA:964,1
DA:969,2
DA:970,3
DA:972,0
DA:973,0
DA:976,3
DA:977,3
DA:978,4
DA:979,9
DA:980,6
DA:983,6
DA:984,3
DA:986,0
DA:987,0
DA:990,3
DA:991,3
DA:992,6
DA:993,0
DA:994,0
DA:997,6
DA:998,1
DA:999,9
DA:1000,3
DA:1001,7
DA:1002,9
DA:1003,3
DA:1005,3
DA:1006,3
DA:1007,2
DA:1010,0
DA:1011,0
DA:1012,0
DA:1013,0
DA:1019,1
DA:1020,2
DA:1021,1
DA:1057,1
DA:1058,1
DA:1059,1
DA:1062,0
DA:1063,0
DA:1064,0
DA:1071,2
DA:1073,2
DA:1080,1
DA:1081,6
DA:1082,5
DA:1087,1
DA:1088,2
DA:1089,2
DA:1090,1
DA:1091,2
DA:1093,0
DA:1117,2
DA:1118,4
DA:1119,4
DA:1120,2
DA:1121,0
DA:1123,0
DA:1152,1
DA:1153,2
DA:1154,1
DA:1155,0
DA:1157,3
DA:1016,0
DA:1017,0
DA:1023,1
DA:1024,2
DA:1025,1
DA:1061,1
DA:1062,1
DA:1063,1
DA:1066,0
DA:1067,0
DA:1068,0
DA:1075,2
DA:1077,2
DA:1084,1
DA:1085,6
DA:1086,5
DA:1091,1
DA:1092,2
DA:1093,2
DA:1094,1
DA:1095,2
DA:1097,0
DA:1121,2
DA:1122,4
DA:1123,4
DA:1124,2
DA:1125,0
DA:1127,0
DA:1156,1
DA:1157,2
DA:1158,1
DA:1159,0
DA:1161,3
DA:1162,1
DA:1163,2
DA:1164,0
DA:1166,2
DA:1179,1
DA:1180,2
DA:1181,2
DA:1182,2
DA:1183,2
DA:1184,5
DA:1187,1
DA:1189,2
DA:1191,4
DA:1194,0
DA:1221,1
DA:1222,1
DA:1223,1
DA:1224,6
DA:1236,1
DA:1238,0
DA:1253,1
DA:1254,1
DA:1166,1
DA:1167,2
DA:1168,0
DA:1170,2
DA:1183,1
DA:1184,2
DA:1185,2
DA:1186,2
DA:1187,2
DA:1188,5
DA:1191,1
DA:1193,2
DA:1195,4
DA:1198,0
DA:1225,1
DA:1226,1
DA:1227,1
DA:1228,6
DA:1240,1
DA:1242,0
DA:1257,1
DA:1258,3
DA:1270,1
DA:1271,1
DA:1274,0
DA:1275,0
DA:1276,0
DA:1258,1
DA:1261,1
DA:1262,3
DA:1274,1
DA:1275,1
DA:1278,0
DA:1279,0
DA:1280,0
DA:1282,0
DA:1283,0
DA:1284,0
DA:1286,0
DA:1300,2
DA:1301,2
DA:1302,6
DA:1303,4
DA:1304,12
DA:1305,8
DA:1307,1
DA:1308,3
DA:1309,1
DA:1312,1
DA:1314,1
DA:1315,4
LF:414
LH:224
DA:1287,0
DA:1288,0
DA:1290,0
DA:1304,2
DA:1305,2
DA:1306,6
DA:1307,3
DA:1308,5
DA:1309,4
DA:1311,1
DA:1312,3
DA:1313,1
DA:1316,3
DA:1318,1
DA:1319,4
LF:419
LH:226
end_of_record
+14 −10
Original line number Diff line number Diff line
@@ -412,22 +412,22 @@ impl Command {
}
impl Config {
    pub fn read(path: PathBuf) -> Option<Config> {
        match Extension::from_string(get_extension(&path)) {
        let content = match Extension::from_string(get_extension(&path)) {
            | Extension::Json => match Config::read_json(path.clone()) {
                | Ok(value) => Some(value),
                | Err(_) => {
                    error!(path = path.to_str().unwrap(), "=> {} Cannot import configuration", Label::not_found());
                    std::process::exit(exitcode::UNAVAILABLE);
                }
                | Err(_) => None,
            },
            | Extension::Yaml => match Config::read_yaml(path.clone()) {
                | Ok(value) => Some(value),
                | Err(_) => {
                    error!(path = path.to_str().unwrap(), "=> {} Cannot import configuration", Label::not_found());
                    std::process::exit(exitcode::UNAVAILABLE);
                }
                | Err(_) => None,
            },
            | Extension::Unknown => unimplemented!("Unknown configuration file extension"),
        };
        if let Some(content) = content {
            Some(content)
        } else {
            error!(path = path.to_str().unwrap(), "=> {} Cannot import configuration", Label::fail());
            std::process::exit(exitcode::UNAVAILABLE);
        }
    }
    /// Import PIPE configuration JSON file
@@ -446,7 +446,7 @@ impl Config {
        let data: serde_json::Result<Config> = serde_json::from_str(&content);
        let label = match data {
            | Ok(_) => Label::output(),
            | Err(_) => Label::fail(),
            | Err(_) => Label::invalid(),
        };
        debug!("=> {} Configuration = {:#?}", label, data.dimmed());
        data
@@ -579,6 +579,10 @@ impl Label {
        let style = Style::new().black().on_yellow();
        " DRY_RUN ■ ".style(style)
    }
    pub fn invalid() -> Styled<&'static &'static str> {
        let style = Style::new().red().on_default_color();
        "INVALID".style(style)
    }
    pub fn fail() -> Styled<&'static &'static str> {
        let style = Style::new().white().on_red();
        " FAIL ".style(style)