+9
Cargo.lock
+9
Cargo.lock
···
3
version = 4
4
5
[[package]]
6
+
name = "json"
7
+
version = "0.12.4"
8
+
source = "registry+https://github.com/rust-lang/crates.io-index"
9
+
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
10
+
11
+
[[package]]
12
name = "tangled-on-commit"
13
version = "0.1.0"
14
+
dependencies = [
15
+
"json",
16
+
]
+1
Cargo.toml
+1
Cargo.toml
+47
-6
src/main.rs
+47
-6
src/main.rs
···
95
}
96
}
97
98
-
if let Some(ref handle) = handle && let Some(ref repo_name) = repo_name && let Some(ref shell) = shell {
99
return Ok(Config {
100
handle: handle.to_string(),
101
repo_name: repo_name.to_string(),
···
103
});
104
}
105
106
-
return Ok(Config {
107
-
handle: handle.unwrap_or(String::new()),
108
-
repo_name: repo_name.unwrap_or(String::new()),
109
-
shell: shell.unwrap_or(String::new()),
110
-
});
111
}
112
113
fn main() -> Result<(), ()> {
···
95
}
96
}
97
98
+
if let Some(ref handle) = handle
99
+
&& let Some(ref repo_name) = repo_name
100
+
&& let Some(ref shell) = shell
101
+
{
102
+
return Ok(Config {
103
+
handle: handle.to_string(),
104
+
repo_name: repo_name.to_string(),
105
+
shell: shell.to_string(),
106
+
});
107
+
}
108
+
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
+
}
122
+
}
123
+
124
+
if let Some(ref handle) = handle
125
+
&& let Some(ref repo_name) = repo_name
126
+
&& let Some(ref shell) = shell
127
+
{
128
return Ok(Config {
129
handle: handle.to_string(),
130
repo_name: repo_name.to_string(),
···
132
});
133
}
134
135
+
// now load from env
136
+
137
+
if let Some(ref handle) = handle
138
+
&& let Some(ref repo_name) = repo_name
139
+
&& let Some(ref shell) = shell
140
+
{
141
+
return Ok(Config {
142
+
handle: handle.to_string(),
143
+
repo_name: repo_name.to_string(),
144
+
shell: shell.to_string(),
145
+
});
146
+
}
147
+
148
+
// couldnt resolve every value
149
+
// print an error and quit
150
+
println!("@{handle:?}/{repo_name:?}: {shell:?}");
151
+
return Err(());
152
}
153
154
fn main() -> Result<(), ()> {