This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.rs
108 lines (95 loc) · 2.83 KB
/
tasks.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) Microsoft Corporation - 2022.
// Licensed under the MIT License.
use chrono::{serde::ts_seconds, DateTime, Utc};
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::io::Result;
use crate::auth::*;
use crate::cli::Cli;
use crate::cli::Commands::*;
use crate::user;
#[derive(Debug, Deserialize, Serialize)]
pub struct Task {
pub text: String,
pub state: String,
pub id: u32,
#[serde(with = "ts_seconds")]
pub updated_at: DateTime<Utc>,
}
impl Task {
pub fn new(id: u32, text: String) -> Task {
let updated_at: DateTime<Utc> = Utc::now();
let state = "todo".to_string();
Task {
text,
state,
id,
updated_at,
}
}
}
pub fn show_tasks(json: &bool) -> Result<()> {
// let token = read_access_token();
// let client = Graph::new(&token);
// let response = client.v1()
// .me().get_user().send();
// println!("response: {:?}", response);
let tasks = collect_tasks();
if *json {
println!(
"Tasks as JSON: {}",
serde_json::to_string(&tasks.unwrap()).unwrap()
);
} else {
println!("Tasks as a table: {:?}", tasks);
}
Ok(())
}
pub fn add_task(new_task: &String) -> Result<()> {
let task = Task::new(99, new_task.to_string());
println!("Adding new task: {:?}", task);
Ok(())
}
pub fn complete_task(id: &u32) -> Result<()> {
println!("Completing task: {}", id);
Ok(())
}
pub fn reopen_task(id: &u32) -> Result<()> {
println!("Reopening task: {}", id);
Ok(())
}
pub fn delete_task(id: &u32) -> Result<()> {
println!("Deleting task: {}", id);
Ok(())
}
fn collect_tasks() -> Result<Vec<Task>> {
let tasks = vec![];
Ok(tasks)
}
pub fn interactive() -> Result<()> {
let mut rl = rustyline::Editor::<()>::new().expect("unable to create interactive shell");
let command = rl.readline("tdi>>");
loop {
match command {
Ok(ref command) => {
let args: Vec<&str> = command.split_whitespace().collect();
let command = Cli::try_parse_from(args).expect("unable to parse");
match &command.command {
Some(Login {}) => login(),
Some(Me { output_format }) => user::show_me(output_format),
Some(Show { json }) => show_tasks(json),
Some(Add { task }) => add_task(task),
Some(Complete { id }) => complete_task(id),
Some(Reopen { id }) => reopen_task(id),
Some(Delete { id }) => delete_task(id),
_ => {
println!("command is {:?}", command);
return Ok(());
}
}?;
}
Err(_) => {}
}
}
//Ok(())
}