add prj
This commit is contained in:
parent
b046374280
commit
4df86eb5c2
3 changed files with 60 additions and 4 deletions
|
@ -152,6 +152,28 @@ impl VikunjaAPI {
|
||||||
serde_json::from_str(&resp).unwrap()
|
serde_json::from_str(&resp).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_project(&self, project_id: ProjectID) {
|
||||||
|
self.delete_request(&format!("/projects/{}", project_id.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_project(
|
||||||
|
&self,
|
||||||
|
title: &str,
|
||||||
|
description: Option<&str>,
|
||||||
|
color: Option<&str>,
|
||||||
|
parent: Option<ProjectID>,
|
||||||
|
) -> Project {
|
||||||
|
let data = serde_json::json!({
|
||||||
|
"description": description,
|
||||||
|
"hex_color": color,
|
||||||
|
"parent_project_id": parent.map(|x| x.0),
|
||||||
|
"title": title
|
||||||
|
});
|
||||||
|
|
||||||
|
let resp = self.put_request("/projects", &data);
|
||||||
|
serde_json::from_str(&resp).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
// labels
|
// labels
|
||||||
pub fn get_all_labels(&self) -> Vec<Label> {
|
pub fn get_all_labels(&self) -> Vec<Label> {
|
||||||
get_all_items(|x| {
|
get_all_items(|x| {
|
||||||
|
|
25
src/args.rs
25
src/args.rs
|
@ -17,9 +17,28 @@ pub fn get_args() -> clap::ArgMatches {
|
||||||
command!()
|
command!()
|
||||||
.name("prj")
|
.name("prj")
|
||||||
.about("Commands about projects")
|
.about("Commands about projects")
|
||||||
.subcommand(command!().name("ls").about("List projects")),
|
.subcommand(command!().name("ls").about("List projects"))
|
||||||
// todo : prj add <project>
|
.subcommand(
|
||||||
// todo : prj rm <project>
|
command!()
|
||||||
|
.name("add")
|
||||||
|
.about("Create a new project")
|
||||||
|
.arg(
|
||||||
|
arg!(-c --color <color> "HEX Color Code for the project")
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
arg!(-d --description <description> "Project description")
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
|
.arg(arg!(-p --parent <parent> "Parent project").required(false))
|
||||||
|
.arg(arg!(<title> "Project title").required(true)),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
command!()
|
||||||
|
.name("rm")
|
||||||
|
.about("Remove a project")
|
||||||
|
.arg(arg!(<project> "Project").required(true)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
command!()
|
command!()
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -28,7 +28,22 @@ fn main() {
|
||||||
Some(("ls", _)) => {
|
Some(("ls", _)) => {
|
||||||
ui::project::list_projects(&api);
|
ui::project::list_projects(&api);
|
||||||
}
|
}
|
||||||
Some(("add", add_prj_arg)) => {}
|
Some(("add", add_prj_arg)) => {
|
||||||
|
let title: &String = add_prj_arg.get_one("title").unwrap();
|
||||||
|
let description: Option<&String> = add_prj_arg.get_one("description");
|
||||||
|
let color: Option<&String> = add_prj_arg.get_one("color");
|
||||||
|
let parent: Option<&String> = add_prj_arg.get_one("parent");
|
||||||
|
api.new_project(
|
||||||
|
title,
|
||||||
|
description.map(|x| x.as_str()),
|
||||||
|
color.map(|x| x.as_str()),
|
||||||
|
parent.map(|x| ProjectID::parse(&api, x).unwrap()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(("rm", rm_prj_arg)) => {
|
||||||
|
let prj: &String = rm_prj_arg.get_one("project").unwrap();
|
||||||
|
api.delete_project(ProjectID::parse(&api, prj).unwrap());
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
ui::project::list_projects(&api);
|
ui::project::list_projects(&api);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue