Use the new toml helpers instead of the toml crate
This commit is contained in:
+7
-10
@@ -1,14 +1,14 @@
|
||||
extern crate elefren;
|
||||
extern crate toml;
|
||||
|
||||
pub use self::elefren::{Data, MastodonClient};
|
||||
|
||||
use std::{error::Error, fs, io};
|
||||
use std::{error::Error, io};
|
||||
|
||||
use self::elefren::{
|
||||
apps::{App, Scopes},
|
||||
Mastodon,
|
||||
Registration,
|
||||
data::toml,
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -19,8 +19,7 @@ fn main() -> Result<(), Box<Error>> {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
|
||||
if let Ok(config) = fs::read_to_string("mastodon-data.toml") {
|
||||
let data: Data = toml::from_str(&config)?;
|
||||
if let Ok(data) = toml::from_file("mastodon-data.toml") {
|
||||
Ok(Mastodon::from(data))
|
||||
} else {
|
||||
register()
|
||||
@@ -39,14 +38,12 @@ pub fn register() -> Result<Mastodon, Box<Error>> {
|
||||
let url = registered.authorize_url()?;
|
||||
|
||||
println!("Click this link to authorize on Mastodon: {}", url);
|
||||
let input = read_line("Paste the returned authorization code: ")?;
|
||||
let code = read_line("Paste the returned authorization code: ")?;
|
||||
|
||||
let code = input.trim();
|
||||
let mastodon = registered.complete(code.to_string())?;
|
||||
let mastodon = registered.complete(code)?;
|
||||
|
||||
// Save app data for using on the next run.
|
||||
let toml = toml::to_string(&*mastodon)?;
|
||||
fs::write("mastodon-data.toml", toml.as_bytes())?;
|
||||
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
||||
|
||||
Ok(mastodon)
|
||||
}
|
||||
@@ -57,5 +54,5 @@ pub fn read_line(message: &str) -> Result<String, Box<Error>> {
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input)?;
|
||||
|
||||
Ok(input)
|
||||
Ok(input.trim().to_string())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user