Initial commit

master
Dustin 2018-06-05 21:01:00 -05:00
commit ff37f5e40f
5 changed files with 1261 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
**/*.rs.bk

1155
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "dchddns"
version = "0.1.0"
authors = ["Dustin C. Hatch <dustin@hatch.name>"]
[dependencies]
clap = "^2"
reqwest = "^0.8.5"
serde = "*"
serde_derive = "*"
toml = "*"

49
src/config.rs Normal file
View File

@ -0,0 +1,49 @@
use ::Error;
use std::fs;
use std::io::prelude::*;
use std::io;
use toml;
#[derive(Debug)]
pub enum ConfigError {
Io(io::Error),
Parse(::toml::de::Error),
}
impl From<io::Error> for ConfigError {
fn from(err: io::Error) -> Self {
ConfigError::Io(err)
}
}
impl From<::toml::de::Error> for ConfigError {
fn from(err: ::toml::de::Error) -> Self {
ConfigError::Parse(err)
}
}
impl From<ConfigError> for Error {
fn from(err: ConfigError) -> Self {
Error::Config(err)
}
}
#[derive(Deserialize)]
pub struct Config {
}
impl Config {
pub fn load(path: &str) -> Result<Self, ConfigError> {
let mut f = fs::File::open(path)?;
let mut data = String::new();
f.read_to_string(&mut data)?;
let config: Config = toml::from_str(&data)?;
Ok(config)
}
}

43
src/main.rs Normal file
View File

@ -0,0 +1,43 @@
#[macro_use]
extern crate serde_derive;
extern crate toml;
#[macro_use]
extern crate clap;
use std::process;
use std::result;
mod config;
#[derive(Debug)]
pub enum Error {
Config(config::ConfigError),
}
type Result<T> = result::Result<T, Error>;
fn run(args: &clap::ArgMatches) -> Result<()> {
let config = config::Config::load(args.value_of("config").unwrap())?;
Ok(())
}
fn main() {
let args = clap::App::new("dchddns")
.version(crate_version!())
.arg(clap::Arg::with_name("config")
.short("c")
.long("config")
.default_value("config.toml")
.help("Path to the configuration file")
)
.get_matches();
if let Err(e) = run(&args) {
eprintln!("{:?}", e);
process::exit(1);
}
}