commit ddf450700975e18c9ce02959b28b15954b98f821
parent 634d7d136b842ea68d038370e7abb9187c727562
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Tue, 3 Sep 2019 10:19:08 -0400
Change Config Format to INI
Diffstat:
4 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -8,4 +8,4 @@ edition = "2018"
chrono = "0.4.8"
clap = "~2.33.0"
dirs = "2.0"
-toml = "0.5.3"-
\ No newline at end of file
+rust-ini = "0.13.0"+
\ No newline at end of file
diff --git a/README.org b/README.org
@@ -2,7 +2,7 @@
A [[https://twtxt.readthedocs.io][twtxt]] command line client written in Rust.
** Configuration
-Configurations are stored as TOML file under =$XDG_CONFIG_HOME/twixter/config=. See =./config.example= for available configurations.
+Configurations are stored in INI format under =$XDG_CONFIG_HOME/twixter/config=. See =./config.example= for available configurations.
** License
Licensed under either of Apache License, Version 2.0 (=./LICENSE-APACHE=) or MIT license (=./LICENSE-MIT=) at your option.
diff --git a/config.example b/config.example
@@ -1,5 +1,6 @@
-nick = "user"
-twtfile = "~/.local/share/twixter/twtxt.txt"
-twturl = "https://example.org/twtxt.txt"
-scp_addr = "user@example.org:~/public_html/twtxt.txt"
+[twtxt]
+nick = user
+twtfile = ~/.local/share/twixter/twtxt.txt
+twturl = https://example.org/twtxt.txt
+scp_addr = user@example.org:~/public_html/twtxt.txt
scp_port = 22
diff --git a/src/main.rs b/src/main.rs
@@ -16,19 +16,16 @@ struct Config {
impl Config {
fn new(config_path: &Path) -> Config {
- use toml::Value;
+ use ini::Ini;
- let mut f = File::open(config_path).unwrap();
- let mut buffer = String::new();
- f.read_to_string(&mut buffer).unwrap();
-
- let config = buffer.parse::<Value>().unwrap();
+ let config = Ini::load_from_file(config_path).unwrap();
+ let twtxt_config = config.section(Some("twtxt".to_owned())).unwrap();
Config {
- nick: config["nick"].as_str().unwrap().to_string(),
- twtfile: config["twtfile"].as_str().unwrap().to_string(),
- twturl: config["twturl"].as_str().unwrap().to_string(),
- scp_addr: config["scp_addr"].as_str().unwrap().to_string(),
- scp_port: config["scp_port"].as_integer().unwrap().to_string(),
+ nick: twtxt_config["nick"].to_owned(),
+ twtfile: twtxt_config["twtfile"].to_owned(),
+ twturl: twtxt_config["twturl"].to_owned(),
+ scp_addr: twtxt_config["scp_addr"].to_owned(),
+ scp_port: twtxt_config["scp_port"].to_owned(),
}
}
}