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