chore: add orgize-sync package
This commit is contained in:
parent
bed20e6112
commit
1fb4d920e5
|
@ -2,6 +2,7 @@
|
||||||
members = [
|
members = [
|
||||||
"orgize",
|
"orgize",
|
||||||
"orgize-demos",
|
"orgize-demos",
|
||||||
|
"orgize-sync",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
26
orgize-sync/Cargo.toml
Normal file
26
orgize-sync/Cargo.toml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
[package]
|
||||||
|
name = "orgize-sync"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["PoiScript <poiscript@gmail.com>"]
|
||||||
|
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"
|
50
orgize-sync/src/conf.rs
Normal file
50
orgize-sync/src/conf.rs
Normal file
|
@ -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<File>,
|
||||||
|
#[cfg(feature = "google_calendar")]
|
||||||
|
pub google_calendar: Option<GoogleCalendarGlobalConf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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<GoogleCalendarConf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_conf_path() -> Result<PathBuf> {
|
||||||
|
let mut path = app_root(
|
||||||
|
AppDataType::UserConfig,
|
||||||
|
&AppInfo {
|
||||||
|
name: "orgize-sync",
|
||||||
|
author: "PoiScript",
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
path.push("conf.toml");
|
||||||
|
Ok(path)
|
||||||
|
}
|
46
orgize-sync/src/error.rs
Normal file
46
orgize-sync/src/error.rs
Normal file
|
@ -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<AppDirsError> for Error {
|
||||||
|
fn from(err: AppDirsError) -> Self {
|
||||||
|
Error::AppDirs(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IOError> for Error {
|
||||||
|
fn from(err: IOError) -> Self {
|
||||||
|
Error::IO(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IsahcError> for Error {
|
||||||
|
fn from(err: IsahcError) -> Self {
|
||||||
|
Error::Http(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HttpError> for Error {
|
||||||
|
fn from(err: HttpError) -> Self {
|
||||||
|
Error::Http(err.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseError> for Error {
|
||||||
|
fn from(err: ParseError) -> Self {
|
||||||
|
Error::Url(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
58
orgize-sync/src/main.rs
Normal file
58
orgize-sync/src/main.rs
Normal file
|
@ -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<PathBuf>,
|
||||||
|
},
|
||||||
|
#[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(())
|
||||||
|
}
|
Loading…
Reference in a new issue