extract-cli #9
3 changed files with 35 additions and 14 deletions
|
@ -14,6 +14,7 @@
|
|||
//! along with tas. If not, see <https://www.gnu.org/licenses/>.
|
||||
//!
|
||||
|
||||
pub mod add;
|
||||
pub mod edit;
|
||||
pub mod finish;
|
||||
pub mod list;
|
||||
|
@ -32,12 +33,7 @@ pub struct Args {
|
|||
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum SubCommand {
|
||||
Add {
|
||||
#[clap(short, long)]
|
||||
link: Option<String>,
|
||||
|
||||
name: String,
|
||||
},
|
||||
Add(self::add::Args),
|
||||
Edit(self::edit::Args),
|
||||
Remove(self::remove::Args),
|
||||
Priority(self::priority::Args),
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::Task;
|
||||
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
#[clap(short, long)]
|
||||
link: Option<String>,
|
||||
|
||||
name: String,
|
||||
}
|
||||
|
||||
pub struct Request {
|
||||
pub args: Args,
|
||||
pub tasks: Vec<Task>,
|
||||
pub tasks_file_path: PathBuf,
|
||||
}
|
||||
|
||||
pub fn execute(mut req: Request) {
|
||||
tasks.push(Task { name, link });
|
||||
|
||||
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
|
||||
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
||||
.unwrap();
|
||||
|
||||
println!("added");
|
||||
}
|
14
src/main.rs
14
src/main.rs
|
@ -52,14 +52,12 @@ fn main() {
|
|||
.unwrap_or_default();
|
||||
|
||||
match args.command {
|
||||
cli::SubCommand::Add { link, name } => {
|
||||
tasks.push(Task { name, link });
|
||||
|
||||
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
|
||||
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
||||
.unwrap();
|
||||
|
||||
println!("added");
|
||||
cli::SubCommand::Add(args) => {
|
||||
cli::add::execute(cli::add::Request {
|
||||
args,
|
||||
tasks,
|
||||
tasks_file_path,
|
||||
});
|
||||
}
|
||||
cli::SubCommand::Edit(args) => {
|
||||
cli::edit::execute(cli::edit::Request {
|
||||
|
|
Loading…
Reference in a new issue