2019-09-15 05:09:59 +01:00
|
|
|
mod conf;
|
|
|
|
mod error;
|
|
|
|
|
2019-09-15 07:39:45 +01:00
|
|
|
use std::fs;
|
2019-09-15 05:09:59 +01:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
2019-09-15 07:39:45 +01:00
|
|
|
use toml::to_string_pretty;
|
2019-09-15 05:09:59 +01:00
|
|
|
|
2019-09-15 07:39:45 +01:00
|
|
|
use crate::conf::{
|
|
|
|
default_config_path, default_env_path, user_cache_path, user_config_path, Conf, EnvConf,
|
|
|
|
};
|
2019-09-15 05:09:59 +01:00
|
|
|
use crate::error::Result;
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
#[structopt(name = "orgize-sync")]
|
|
|
|
struct Opt {
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
subcommand: Cmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
enum Cmd {
|
|
|
|
#[structopt(name = "init")]
|
|
|
|
Init,
|
|
|
|
#[structopt(name = "sync")]
|
|
|
|
Sync {
|
|
|
|
#[structopt(long = "skip-google-calendar")]
|
|
|
|
skip_google_calendar: bool,
|
|
|
|
#[structopt(long = "skip-toggl")]
|
|
|
|
skip_toggl: bool,
|
|
|
|
#[structopt(short = "c", long = "conf", parse(from_os_str))]
|
|
|
|
conf_path: Option<PathBuf>,
|
|
|
|
},
|
|
|
|
#[structopt(name = "conf")]
|
2019-09-15 07:39:45 +01:00
|
|
|
Conf {
|
|
|
|
#[structopt(short = "c", long = "conf", parse(from_os_str))]
|
|
|
|
conf_path: Option<PathBuf>,
|
|
|
|
},
|
2019-09-15 05:09:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
let opt = Opt::from_args();
|
|
|
|
|
|
|
|
match opt.subcommand {
|
2019-09-15 07:39:45 +01:00
|
|
|
Cmd::Init => {
|
|
|
|
fs::create_dir_all(user_config_path())?;
|
|
|
|
fs::create_dir_all(user_cache_path())?;
|
|
|
|
|
|
|
|
let default_env_path = default_env_path();
|
|
|
|
let default_config_path = default_config_path();
|
|
|
|
|
|
|
|
if default_env_path.as_path().exists() {
|
|
|
|
println!(
|
|
|
|
"{} already existed, skipping ...",
|
|
|
|
default_env_path.as_path().display()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
println!("Creating {} ...", default_env_path.as_path().display());
|
|
|
|
fs::write(default_env_path.clone(), "")?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if default_config_path.as_path().exists() {
|
|
|
|
println!(
|
|
|
|
"{} already existed, skipping ...",
|
|
|
|
default_config_path.as_path().display()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
println!("Creating {} ...", default_config_path.as_path().display());
|
|
|
|
fs::write(
|
|
|
|
default_config_path,
|
|
|
|
to_string_pretty(&EnvConf {
|
|
|
|
env_path: default_env_path,
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
}
|
2019-09-15 05:09:59 +01:00
|
|
|
Cmd::Sync {
|
|
|
|
conf_path,
|
|
|
|
skip_google_calendar,
|
|
|
|
skip_toggl,
|
|
|
|
} => {
|
2019-09-15 07:39:45 +01:00
|
|
|
let conf = Conf::new(conf_path)?;
|
2019-09-15 05:09:59 +01:00
|
|
|
|
|
|
|
if cfg!(feature = "google_calendar") && !skip_google_calendar {}
|
|
|
|
|
|
|
|
if cfg!(feature = "toggl") && !skip_toggl {}
|
|
|
|
}
|
2019-09-15 07:39:45 +01:00
|
|
|
Cmd::Conf { conf_path } => {
|
|
|
|
let conf = Conf::new(conf_path)?;
|
|
|
|
|
|
|
|
println!("{}", to_string_pretty(&conf)?);
|
|
|
|
}
|
2019-09-15 05:09:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|