1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mod error;
pub mod cli;
pub mod conf;
pub use cli::Command;
pub use conf::Config;
pub use error::Fail;
static mut VERSION: &str = "";
pub fn version() -> &'static str {
unsafe { VERSION }
}
pub fn init_version(cargo_toml: &'static str) -> &str {
let blocks: Vec<&str> = cargo_toml.split('"').collect();
let version_string = match blocks.get(3) {
Some(version_string) => {
if version_string.split('.').count() == 3 {
if blocks[2].contains("version") {
version_string
} else {
check_version(&blocks, 0)
}
} else {
check_version(&blocks, 0)
}
}
None => check_version(&blocks, 0),
};
unsafe {
VERSION = version_string;
}
version()
}
fn check_version(blocks: &[&'static str], index: usize) -> &'static str {
match blocks.get(index) {
Some(version_string) => {
if version_string.split('.').count() == 3 {
match blocks.get(index - 1) {
Some(previous) => {
if previous.contains("version") {
version_string
} else {
check_version(&blocks, index + 1)
}
}
None => check_version(&blocks, index + 1),
}
} else {
check_version(blocks, index + 1)
}
}
None => "0.0.0",
}
}