Skip to content

Commit

Permalink
fix: update prettytable-rs version to 0.10.0 (#29)
Browse files Browse the repository at this point in the history
* fix: update prettytable-rs version to 0.10.0

* chore: update clippy warnings

Signed-off-by: Hemanth Krishna <hkpdev008@gmail.com>

---------

Signed-off-by: Hemanth Krishna <hkpdev008@gmail.com>
Co-authored-by: Hemanth Krishna <hkpdev008@gmail.com>
  • Loading branch information
janekx21 and DarthBenro008 committed Feb 9, 2024
1 parent c74e5e6 commit 908833a
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 101 deletions.
262 changes: 179 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dialoguer = "0.8.0"
console = "0.14.1"
sled = "0.34.6"
bincode = "1.3.3"
prettytable-rs = "0.8.0"
prettytable-rs = "0.10.0"

[dependencies.serde]
version = "1.0.64"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Secrets {{
}

fn generate_module() -> Result<(), std::io::Error> {
let mut module = std::fs::File::create(&format!("src/{}.rs", "secrets"))?;
let mut module = std::fs::File::create(format!("src/{}.rs", "secrets"))?;
write_link_info_type(&mut module)?;
Ok(())
}
Expand Down
36 changes: 27 additions & 9 deletions src/handlers/task_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ impl TaskManager {
Ok(())
}

pub fn add_task(&self, title: Option<String>, notes: Option<String>, completed: bool) -> anyhow::Result<()> {
pub fn add_task(
&self,
title: Option<String>,
notes: Option<String>,
completed: bool,
) -> anyhow::Result<()> {
let task = match title {
Some(t) => self.create_task_without_prompts(t, notes, completed),
None => self.create_task_with_prompts(notes, completed)?
None => self.create_task_with_prompts(notes, completed)?,
};
let resp = &self.client.add_task(task);
match resp {
Expand All @@ -41,31 +46,44 @@ impl TaskManager {
Ok(())
}

fn create_task_without_prompts(&self, title: String, notes: Option<String>, completed: bool) -> Tasks {
fn create_task_without_prompts(
&self,
title: String,
notes: Option<String>,
completed: bool,
) -> Tasks {
let status = if completed {
String::from("completed")
} else {
String::from("needsAction")
};
Tasks::new(None, title, notes.unwrap_or_else(||String::from("")), status)
Tasks::new(
None,
title,
notes.unwrap_or_else(|| String::from("")),
status,
)
}

fn create_task_with_prompts (&self, notes: Option<String>, done: bool) -> anyhow::Result<Tasks> {
fn create_task_with_prompts(&self, notes: Option<String>, done: bool) -> anyhow::Result<Tasks> {
let title: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Title of the task")
.with_initial_text("task")
.allow_empty(false)
.interact_text()?;

let notes: String = notes.map(Result::Ok).unwrap_or_else(|| Input::with_theme(&ColorfulTheme::default())

let notes: String = notes.map(Result::Ok).unwrap_or_else(|| {
Input::with_theme(&ColorfulTheme::default())
.with_prompt("Note for task")
.with_initial_text("note")
.allow_empty(true)
.interact_text()
)?;
})?;

let items = vec!["No", "Yes"];
let completed = if done { 1_usize } else {
let completed = if done {
1_usize
} else {
Select::with_theme(&ColorfulTheme::default())
.with_prompt("Is the task completed?")
.items(&items)
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tasklist_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TaskListManager {
let resp = &self.client.fetch_tasklist(false);
match resp {
Ok(data) => Ok(data.items.clone()),
Err(_err) => Err(anyhow!("Cannot fetch tasklists!")),
Err(err) => Err(anyhow!("Cannot fetch tasklists! {}", err)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn get_token(
let code_pair = url
.query_pairs()
.find(|pair| {
let &(ref key, _) = pair;
let (key, _) = pair;
key == "code"
})
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/service/google_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl GoogleApiClient {
}

pub fn format_base_url(base_url: &str, route: String) -> String {
return format!("{}{}", base_url, route);
format!("{}{}", base_url, route)
}

pub fn format_task_url(base_url: &str, route: String, task_id: String) -> String {
return format!("{}/{}", format_base_url(base_url, route), task_id);
format!("{}/{}", format_base_url(base_url, route), task_id)
}

pub fn format_specific_task_url(
Expand All @@ -72,9 +72,9 @@ pub fn format_specific_task_url(
task_id: String,
task_route: String,
) -> String {
return format!(
format!(
"{}/{}",
format_task_url(base_url, route, task_id),
task_route
);
)
}
2 changes: 1 addition & 1 deletion src/service/google_tasklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ApiTaskList for GoogleApiClient {
}
let task_list = resp.json::<TaskListResponse>()?;
if default {
let first_tasklist = task_list.items.get(0);
let first_tasklist = task_list.items.first();
match first_tasklist {
Some(task_list) => {
self.localdb.insert_default_tasklist(
Expand Down

0 comments on commit 908833a

Please sign in to comment.