add label new
This commit is contained in:
parent
09f6dd0625
commit
c469386c6a
4 changed files with 40 additions and 6 deletions
|
@ -151,6 +151,19 @@ impl VikunjaAPI {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn new_label(&self, title: &str, description: Option<&str>, color: Option<&str>) -> Label {
|
||||
let resp = self.put_request(
|
||||
"/labels",
|
||||
&serde_json::json!({
|
||||
"title": title,
|
||||
"description": description,
|
||||
"hex_color": color
|
||||
}),
|
||||
);
|
||||
|
||||
serde_json::from_str(&resp).unwrap()
|
||||
}
|
||||
|
||||
// tasks
|
||||
pub fn get_task_page(&self, page: usize) -> Vec<Task> {
|
||||
let resp = self.get_request(&format!("/tasks/all?page={page}"));
|
||||
|
|
19
src/args.rs
19
src/args.rs
|
@ -36,10 +36,21 @@ pub fn get_args() -> clap::ArgMatches {
|
|||
command!()
|
||||
.name("label")
|
||||
.about("Manage labels")
|
||||
.subcommand(command!().name("ls").about("List all labels")),
|
||||
// todo : label new
|
||||
// todo : label rm
|
||||
// todo : label <label> <task>
|
||||
.subcommand(command!().name("ls").about("List all labels"))
|
||||
.subcommand(
|
||||
command!()
|
||||
.name("new")
|
||||
.about("Create a new label")
|
||||
.arg(
|
||||
arg!(-c --color <color> "HEX Color Code for the label").required(false),
|
||||
)
|
||||
.arg(
|
||||
arg!(-d --description <description> "Description for the label")
|
||||
.required(false),
|
||||
)
|
||||
.arg(arg!(<title> "Label title").required(true)),
|
||||
), // todo : label rm
|
||||
// todo : label <label> <task>
|
||||
)
|
||||
.subcommand(
|
||||
command!()
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -29,7 +29,17 @@ fn main() {
|
|||
Some(("ls", _)) => {
|
||||
ui::print_all_labels(&api);
|
||||
}
|
||||
Some(("new", new_label_arg)) => {}
|
||||
Some(("new", new_label_arg)) => {
|
||||
let description: Option<&String> = new_label_arg.get_one("description");
|
||||
let color: Option<&String> = new_label_arg.get_one("color");
|
||||
let title: &String = new_label_arg.get_one("title").unwrap();
|
||||
|
||||
api.new_label(
|
||||
title.as_str(),
|
||||
description.map(|x| x.as_str()),
|
||||
color.map(|x| x.as_str()),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// todo : label tasks
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub fn time_since(event: DateTime<Utc>) -> String {
|
|||
}
|
||||
|
||||
fn print_label(label: &Label) {
|
||||
let color = hex_to_color(&label.hex_color).unwrap();
|
||||
let color = hex_to_color(&label.hex_color).unwrap_or(Color::Reset);
|
||||
print_color_bg(color, label.title.trim());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue