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
|
// tasks
|
||||||
pub fn get_task_page(&self, page: usize) -> Vec<Task> {
|
pub fn get_task_page(&self, page: usize) -> Vec<Task> {
|
||||||
let resp = self.get_request(&format!("/tasks/all?page={page}"));
|
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!()
|
command!()
|
||||||
.name("label")
|
.name("label")
|
||||||
.about("Manage labels")
|
.about("Manage labels")
|
||||||
.subcommand(command!().name("ls").about("List all labels")),
|
.subcommand(command!().name("ls").about("List all labels"))
|
||||||
// todo : label new
|
.subcommand(
|
||||||
// todo : label rm
|
command!()
|
||||||
// todo : label <label> <task>
|
.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(
|
.subcommand(
|
||||||
command!()
|
command!()
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -29,7 +29,17 @@ fn main() {
|
||||||
Some(("ls", _)) => {
|
Some(("ls", _)) => {
|
||||||
ui::print_all_labels(&api);
|
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
|
// todo : label tasks
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub fn time_since(event: DateTime<Utc>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_label(label: &Label) {
|
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());
|
print_color_bg(color, label.title.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue