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()
|
||||
}
|
||||
|
||||
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
|
||||
pub fn get_all_labels(&self) -> Vec<Label> {
|
||||
get_all_items(|x| {
|
||||
|
|
25
src/args.rs
25
src/args.rs
|
@ -17,9 +17,28 @@ pub fn get_args() -> clap::ArgMatches {
|
|||
command!()
|
||||
.name("prj")
|
||||
.about("Commands about projects")
|
||||
.subcommand(command!().name("ls").about("List projects")),
|
||||
// todo : prj add <project>
|
||||
// todo : prj rm <project>
|
||||
.subcommand(command!().name("ls").about("List projects"))
|
||||
.subcommand(
|
||||
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(
|
||||
command!()
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -28,7 +28,22 @@ fn main() {
|
|||
Some(("ls", _)) => {
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue