Compare commits
5 Commits
a16fdd3c5f
...
5ce6fb8f60
Author | SHA1 | Date | |
---|---|---|---|
5ce6fb8f60 | |||
56e02021c7 | |||
40d74ef0bf | |||
900d6ae3f0 | |||
52a12426e3 |
43
src/main.rs
43
src/main.rs
@ -95,9 +95,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// gst stamp --start --task NUM --description "desc" --dstart "20120101" --dend "20120101"
|
// gst stamp [--start | --stop | --update]
|
||||||
// gst stamp --stop
|
|
||||||
// gst stamp --update --description "desc" --dstart "20120101" --dend "20120101"
|
|
||||||
("stamp", Some(_matches)) => {
|
("stamp", Some(_matches)) => {
|
||||||
let start = _matches.occurrences_of("start");
|
let start = _matches.occurrences_of("start");
|
||||||
let stop = _matches.occurrences_of("stop");
|
let stop = _matches.occurrences_of("stop");
|
||||||
@ -108,21 +106,14 @@ fn main() {
|
|||||||
let description: &str = _matches.value_of("description").unwrap_or("").trim();
|
let description: &str = _matches.value_of("description").unwrap_or("").trim();
|
||||||
let dstart: &str = _matches.value_of("dstart").unwrap_or("").trim();
|
let dstart: &str = _matches.value_of("dstart").unwrap_or("").trim();
|
||||||
let dend: &str = _matches.value_of("dend").unwrap_or("").trim();
|
let dend: &str = _matches.value_of("dend").unwrap_or("").trim();
|
||||||
|
// gst stamp --start --task NUM --description "desc" --dstart "20120101" --dend "20120101"
|
||||||
if start == 1 {
|
if start == 1 {
|
||||||
console::info("Add a new stamp");
|
console::info("Add a new stamp");
|
||||||
match task {
|
match task {
|
||||||
0 => panic!("Need some task number to add the stamp"),
|
0 => panic!("Need some task number to add the stamp"),
|
||||||
_ => {
|
_ => {
|
||||||
let stamp = Stamp {
|
let stamp = Stamp::new(&config_file, dstart, dend, description, task, "");
|
||||||
id: 0,
|
let added = stamp.api_post(&config_file, "stamp/add");
|
||||||
user_id: 0,
|
|
||||||
project_id: 0,
|
|
||||||
start: Some(dstart.to_string()),
|
|
||||||
end: Some(dend.to_string()),
|
|
||||||
description: Some(description.to_string()),
|
|
||||||
task_id: Some(task),
|
|
||||||
};
|
|
||||||
let added = stamp.add(&config_file);
|
|
||||||
match added.status() {
|
match added.status() {
|
||||||
reqwest::StatusCode::OK => println!("OK"),
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
err => println!("KO: {:?}, something happened", err),
|
err => println!("KO: {:?}, something happened", err),
|
||||||
@ -130,31 +121,25 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// gst stamp --stop
|
||||||
else if stop == 1 {
|
else if stop == 1 {
|
||||||
console::info("Stop last stamp");
|
console::info("Stop last stamp");
|
||||||
let stamp = Stamp {
|
let stamp = Stamp::new(&config_file, "", "", "", 0, "");
|
||||||
id: 0,
|
let stopped = stamp.api_post(&config_file, "stamp/stop");
|
||||||
user_id: 0,
|
|
||||||
project_id: 0,
|
|
||||||
start: Some("".to_string()),
|
|
||||||
end: Some("".to_string()),
|
|
||||||
description: Some("".to_string()),
|
|
||||||
task_id: Some(0),
|
|
||||||
};
|
|
||||||
let stopped = stamp.stop(&config_file);
|
|
||||||
match stopped.status() {
|
match stopped.status() {
|
||||||
reqwest::StatusCode::OK => println!("OK"),
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
err => println!("KO: {:?}, something happened", err),
|
err => println!("KO: {:?}, something happened", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// gst stamp --update --description "desc" --dstart "20120101" --dend "20120101"
|
||||||
else if update == 1 {
|
else if update == 1 {
|
||||||
console::info("Update last stamp");
|
console::info("Update last stamp");
|
||||||
// let stamp = {
|
let stamp = Stamp::new(&config_file, dstart, dend, description, task, "");
|
||||||
// // description
|
let updated = stamp.api_post(&config_file, "stamp/update");
|
||||||
// // dstart
|
match updated.status() {
|
||||||
// // dend
|
reqwest::StatusCode::OK => println!("OK"),
|
||||||
// };
|
err => println!("KO: {:?}, something happened", err),
|
||||||
// stamp.update();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use toml;
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub key: String,
|
pub key: String,
|
||||||
|
pub user_id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -16,6 +17,7 @@ impl Config {
|
|||||||
Config {
|
Config {
|
||||||
url: "https://uri".to_string(),
|
url: "https://uri".to_string(),
|
||||||
key: "s3cr3tk3y".to_string(),
|
key: "s3cr3tk3y".to_string(),
|
||||||
|
user_id: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn parse(&mut self, config_file: &PathBuf) -> Config {
|
pub fn parse(&mut self, config_file: &PathBuf) -> Config {
|
||||||
|
@ -12,34 +12,40 @@ pub struct Stamp {
|
|||||||
pub end: Option<String>,
|
pub end: Option<String>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub task_id: Option<u32>,
|
pub task_id: Option<u32>,
|
||||||
|
pub duration: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stamp {
|
impl Stamp {
|
||||||
#[tokio::main]
|
pub fn new(config_file: &PathBuf,
|
||||||
pub async fn add(&self, config_file: &PathBuf) -> reqwest::Response {
|
dstart: &str,
|
||||||
|
dend: &str,
|
||||||
|
description: &str,
|
||||||
|
task: u32,
|
||||||
|
duration: &str,
|
||||||
|
) -> Stamp {
|
||||||
// Config
|
// Config
|
||||||
let mut default_config = config::Config::default();
|
let mut default_config = config::Config::default();
|
||||||
let config = default_config.parse(&config_file);
|
let config = default_config.parse(&config_file);
|
||||||
|
Stamp {
|
||||||
// Call api
|
id: 0,
|
||||||
let endpoint = format!("{}{}", &config.url, "stamp/add");
|
user_id: config.user_id,
|
||||||
let client = reqwest::Client::new();
|
project_id: 0,
|
||||||
let res = client.post(endpoint)
|
start: Some(dstart.to_string()),
|
||||||
.header("Authorization", &config.key)
|
end: Some(dend.to_string()),
|
||||||
.json(&self)
|
description: Some(description.to_string()),
|
||||||
.send()
|
task_id: Some(task),
|
||||||
.await;
|
duration: Some(duration.to_string()),
|
||||||
|
|
||||||
res.unwrap()
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn stop(&self, config_file: &PathBuf) -> reqwest::Response {
|
pub async fn api_post(&self, config_file: &PathBuf, endpoint: &str) -> reqwest::Response {
|
||||||
// Config
|
// Config
|
||||||
let mut default_config = config::Config::default();
|
let mut default_config = config::Config::default();
|
||||||
let config = default_config.parse(&config_file);
|
let config = default_config.parse(&config_file);
|
||||||
|
|
||||||
// Call api
|
// Call api
|
||||||
let endpoint = format!("{}{}", &config.url, "stamp/stop");
|
let endpoint = format!("{}{}", &config.url, String::from(endpoint));
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let res = client.post(endpoint)
|
let res = client.post(endpoint)
|
||||||
.header("Authorization", &config.key)
|
.header("Authorization", &config.key)
|
||||||
@ -77,19 +83,30 @@ impl Stamps {
|
|||||||
let stamps = parsed.json::<Stamps>().unwrap();
|
let stamps = parsed.json::<Stamps>().unwrap();
|
||||||
// eprintln!("{:#?}", stamps);
|
// eprintln!("{:#?}", stamps);
|
||||||
for stamp in stamps.data {
|
for stamp in stamps.data {
|
||||||
|
let mut open: String = String::from("");
|
||||||
|
match stamp.end {
|
||||||
|
None => open = "⏸️ ".to_string(),
|
||||||
|
_ => {
|
||||||
|
let op: String = format_args!("{duration}",
|
||||||
|
duration=stamp.duration.unwrap().to_string()
|
||||||
|
).to_string();
|
||||||
|
open = op;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let output: String = format_args!("⏳ ({id}) {open} - {description}",
|
||||||
|
open=open,
|
||||||
|
id=stamp.id,
|
||||||
|
description=stamp.description.unwrap()
|
||||||
|
).to_string();
|
||||||
match project {
|
match project {
|
||||||
0 => {
|
0 => {
|
||||||
println!("⏳ ({id}) {description}",
|
println!("{}", output);
|
||||||
id=stamp.id,
|
|
||||||
description=stamp.description.unwrap());
|
|
||||||
if last != 0 { break; }
|
if last != 0 { break; }
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
if project == stamp.project_id {
|
if project == stamp.project_id {
|
||||||
println!("⏳ ({id}) {description}",
|
println!("{}", output);
|
||||||
id=stamp.id,
|
|
||||||
description=stamp.description.unwrap());
|
|
||||||
if last != 0 { break; }
|
if last != 0 { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user