Listen to git commits for a specific repo and run a shell command

Load data from env variables

vielle.dev f2c2aa96 df72cb91

verified
Changed files
+20 -3
src
+20 -3
src/main.rs
··· 14 14 // if omitted, fallback to a local `tangled-on-commit.json` file 15 15 // if key omitted or file not found, fall back to env 16 16 // if env omitted, error out and quit 17 + // note: shell is not loaded from env (to avoid the user unknowingly executing scripts) 17 18 18 19 // if any args are `-h` || `--help` display help and quit 19 20 for arg in std::env::args() { ··· 109 110 // now load config 110 111 if let Ok(file) = std::fs::read_to_string("./tangled-on-commit.json") { 111 112 if let Ok(parsed) = json::parse(&file) { 112 - if let Some(json_handle) = parsed["handle"].as_str() { 113 + if handle.is_none() 114 + && let Some(json_handle) = parsed["handle"].as_str() 115 + { 113 116 handle = Some(String::from(json_handle)) 114 117 } 115 - if let Some(json_repo_name) = parsed["repo_name"].as_str() { 118 + if repo_name.is_none() 119 + && let Some(json_repo_name) = parsed["repo_name"].as_str() 120 + { 116 121 repo_name = Some(String::from(json_repo_name)) 117 122 } 118 - if let Some(json_shell) = parsed["shell"].as_str() { 123 + if shell.is_none() 124 + && let Some(json_shell) = parsed["shell"].as_str() 125 + { 119 126 shell = Some(String::from(json_shell)) 120 127 } 121 128 } ··· 133 140 } 134 141 135 142 // now load from env 143 + if handle.is_none() 144 + && let Ok(env_handle) = std::env::var("TANGLED_ON_COMMIT_HANDLE") 145 + { 146 + handle = Some(String::from(env_handle)) 147 + } 148 + if repo_name.is_none() 149 + && let Ok(env_repo_name) = std::env::var("TANGLED_ON_COMMIT_REPO_NAME") 150 + { 151 + repo_name = Some(String::from(env_repo_name)) 152 + } 136 153 137 154 if let Some(ref handle) = handle 138 155 && let Some(ref repo_name) = repo_name