diff --git a/Cargo.toml b/Cargo.toml index 903ba10..0cbba1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "orgize", "orgize-demos", + "orgize-sync", ] [profile.release] diff --git a/orgize-sync/Cargo.toml b/orgize-sync/Cargo.toml new file mode 100644 index 0000000..36ff904 --- /dev/null +++ b/orgize-sync/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "orgize-sync" +version = "0.1.0" +authors = ["PoiScript "] +edition = "2018" + +[package.metadata.docs.rs] +all-features = true + +[features] +default = ["google_calendar", "toggl"] +google_calendar = [] +toggl = [] + +[dependencies] +app_dirs = "1.2.1" +chrono = { version = "0.4.9", features = ["serde"] } +colored = "1.8.0" +futures-preview = "=0.3.0-alpha.18" +isahc = { version = "0.7.3", default-features = false, features = ["json", "http2", "static-curl"] } +orgize = { path = "../orgize", default-features = false, features = ["chrono"] } +serde = { version = "1.0.100", features = ["derive"] } +serde_json = "1.0.40" +structopt = "0.3.1" +toml = "0.5.3" +url = "2.1.0" diff --git a/orgize-sync/src/conf.rs b/orgize-sync/src/conf.rs new file mode 100644 index 0000000..f95e87a --- /dev/null +++ b/orgize-sync/src/conf.rs @@ -0,0 +1,50 @@ +use app_dirs::{app_root, AppDataType, AppInfo}; +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + +use crate::error::Result; + +#[derive(Serialize, Deserialize)] +pub struct Conf { + pub files: Vec, + #[cfg(feature = "google_calendar")] + pub google_calendar: Option, +} + +#[derive(Serialize, Deserialize)] +#[cfg(feature = "google_calendar")] +pub struct GoogleCalendarGlobalConf { + pub client_id: String, + pub client_secret: String, + pub token_dir: String, + pub token_filename: String, + pub property: String, +} + +#[derive(Serialize, Deserialize)] +#[cfg(feature = "google_calendar")] +pub struct GoogleCalendarConf { + pub calendar: String, + pub append_new: bool, + pub append_headline: String, +} + +#[derive(Serialize, Deserialize)] +pub struct File { + pub path: String, + pub name: String, + #[cfg(feature = "google_calendar")] + pub google_calendar: Option, +} + +pub fn default_conf_path() -> Result { + let mut path = app_root( + AppDataType::UserConfig, + &AppInfo { + name: "orgize-sync", + author: "PoiScript", + }, + )?; + path.push("conf.toml"); + Ok(path) +} diff --git a/orgize-sync/src/error.rs b/orgize-sync/src/error.rs new file mode 100644 index 0000000..b53f32c --- /dev/null +++ b/orgize-sync/src/error.rs @@ -0,0 +1,46 @@ +use app_dirs::AppDirsError; +use isahc::http::Error as HttpError; +use isahc::Error as IsahcError; +use std::convert::From; +use std::io::Error as IOError; +use url::ParseError; + +#[derive(Debug)] +pub enum Error { + AppDirs(AppDirsError), + IO(IOError), + Http(IsahcError), + Url(ParseError), +} + +impl From for Error { + fn from(err: AppDirsError) -> Self { + Error::AppDirs(err) + } +} + +impl From for Error { + fn from(err: IOError) -> Self { + Error::IO(err) + } +} + +impl From for Error { + fn from(err: IsahcError) -> Self { + Error::Http(err) + } +} + +impl From for Error { + fn from(err: HttpError) -> Self { + Error::Http(err.into()) + } +} + +impl From for Error { + fn from(err: ParseError) -> Self { + Error::Url(err) + } +} + +pub type Result = std::result::Result; diff --git a/orgize-sync/src/main.rs b/orgize-sync/src/main.rs new file mode 100644 index 0000000..480bf3b --- /dev/null +++ b/orgize-sync/src/main.rs @@ -0,0 +1,58 @@ +mod conf; +mod error; + +use std::path::PathBuf; +use structopt::StructOpt; + +use crate::conf::default_conf_path; +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, + }, + #[structopt(name = "conf")] + Conf, +} + +fn main() -> Result<()> { + let opt = Opt::from_args(); + + match opt.subcommand { + Cmd::Sync { + conf_path, + skip_google_calendar, + skip_toggl, + } => { + let conf_path = conf_path + .map(Result::Ok) + .unwrap_or_else(default_conf_path)?; + + println!("{:#?}", conf_path); + + if cfg!(feature = "google_calendar") && !skip_google_calendar {} + + if cfg!(feature = "toggl") && !skip_toggl {} + } + Cmd::Init => (), + Cmd::Conf => (), + } + + Ok(()) +}