parent
8d21df094c
commit
238e4b0b03
9 changed files with 69 additions and 27 deletions
|
@ -57,4 +57,8 @@ pub fn print_task_detail(task: &domain::Task) {
|
||||||
if let Some(link) = task.link.as_ref() {
|
if let Some(link) = task.link.as_ref() {
|
||||||
println!(" link: {}", link);
|
println!(" link: {}", link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(path) = task.path.as_ref() {
|
||||||
|
println!(" path: {}", path.to_string_lossy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,14 @@ use crate::{
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
|
#[clap(short, long)]
|
||||||
|
group: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
link: Option<String>,
|
link: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
group: Option<String>,
|
path: Option<String>,
|
||||||
|
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
@ -19,6 +22,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
link: args.link,
|
link: args.link,
|
||||||
group: args.group,
|
group: args.group,
|
||||||
|
path: args.path.map(std::fs::canonicalize).transpose().unwrap(),
|
||||||
index: None,
|
index: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::cli::print_task_detail;
|
use crate::cli::print_task_detail;
|
||||||
use crate::repo::{self, Repository};
|
use crate::repo::{self, Repository};
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[clap(short, long)]
|
|
||||||
link: Option<String>,
|
|
||||||
#[clap(long)]
|
|
||||||
no_link: bool,
|
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
|
@ -16,6 +13,16 @@ pub struct Args {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
no_group: bool,
|
no_group: bool,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
link: Option<String>,
|
||||||
|
#[clap(long)]
|
||||||
|
no_link: bool,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
#[clap(long)]
|
||||||
|
no_path: bool,
|
||||||
|
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +41,12 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
args.idx,
|
args.idx,
|
||||||
repo::UpdateTaskData {
|
repo::UpdateTaskData {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
|
||||||
group: args.no_group.then(|| None).or_else(|| args.group.map(Some)),
|
group: args.no_group.then(|| None).or_else(|| args.group.map(Some)),
|
||||||
|
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
||||||
|
path: args
|
||||||
|
.no_path
|
||||||
|
.then(|| None)
|
||||||
|
.or_else(|| args.path.map(std::fs::canonicalize).transpose().ok()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
match res {
|
match res {
|
||||||
|
|
|
@ -12,13 +12,6 @@ pub fn execute(repo: impl Repository) {
|
||||||
Ok(task) => task,
|
Ok(task) => task,
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo.stop_task() {
|
println!("The task was paused successfully");
|
||||||
Ok(_) => {
|
print_task_detail(&task);
|
||||||
println!("The task was paused successfully");
|
|
||||||
print_task_detail(&task);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Cannot pause the task: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,9 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
let res = repo.insert_task(repo::InsertTaskData {
|
let res = repo.insert_task(repo::InsertTaskData {
|
||||||
index: Some(new_idx),
|
index: Some(new_idx),
|
||||||
name: target.name,
|
name: target.name,
|
||||||
link: target.link,
|
|
||||||
group: target.group,
|
group: target.group,
|
||||||
|
link: target.link,
|
||||||
|
path: target.path,
|
||||||
});
|
});
|
||||||
match res {
|
match res {
|
||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
|
|
|
@ -8,6 +8,9 @@ pub struct Args {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
open: bool,
|
open: bool,
|
||||||
|
|
||||||
|
#[clap(long)]
|
||||||
|
print_path: bool,
|
||||||
|
|
||||||
idx: Option<usize>,
|
idx: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +21,17 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
Err(err) => return eprintln!("Cannot start task: {}", err),
|
Err(err) => return eprintln!("Cannot start task: {}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("The task was started successfully");
|
if args.print_path {
|
||||||
print_task_detail(&task);
|
println!(
|
||||||
|
"{}",
|
||||||
|
task.path
|
||||||
|
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
|
||||||
|
.to_string_lossy()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
println!("The task was started successfully");
|
||||||
|
print_task_detail(&task);
|
||||||
|
}
|
||||||
|
|
||||||
if let (Some(link), true) = (task.link.as_ref(), args.open) {
|
if let (Some(link), true) = (task.link.as_ref(), args.open) {
|
||||||
log::debug!("opening link...");
|
log::debug!("opening link...");
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub type TaskId = usize;
|
pub type TaskId = usize;
|
||||||
|
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub link: Option<String>,
|
|
||||||
pub group: Option<String>,
|
pub group: Option<String>,
|
||||||
|
pub link: Option<String>,
|
||||||
|
pub path: Option<PathBuf>,
|
||||||
// created_at
|
// created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::domain;
|
use crate::domain;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -23,15 +25,17 @@ impl std::error::Error for Error {}
|
||||||
|
|
||||||
pub struct InsertTaskData {
|
pub struct InsertTaskData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub link: Option<String>,
|
|
||||||
pub group: Option<String>,
|
pub group: Option<String>,
|
||||||
|
pub link: Option<String>,
|
||||||
|
pub path: Option<PathBuf>,
|
||||||
pub index: Option<usize>,
|
pub index: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UpdateTaskData {
|
pub struct UpdateTaskData {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub link: Option<Option<String>>,
|
|
||||||
pub group: Option<Option<String>>,
|
pub group: Option<Option<String>>,
|
||||||
|
pub link: Option<Option<String>>,
|
||||||
|
pub path: Option<Option<PathBuf>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Repository {
|
pub trait Repository {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::domain;
|
use crate::domain;
|
||||||
use crate::repo::{Error, InsertTaskData, Repository, UpdateTaskData};
|
use crate::repo::{Error, InsertTaskData, Repository, UpdateTaskData};
|
||||||
|
@ -10,8 +11,9 @@ use xdg::BaseDirectories;
|
||||||
#[derive(Deserialize, Serialize, Clone)]
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
name: String,
|
name: String,
|
||||||
link: Option<String>,
|
|
||||||
group: Option<String>,
|
group: Option<String>,
|
||||||
|
link: Option<String>,
|
||||||
|
path: Option<String>,
|
||||||
// created_at
|
// created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +21,9 @@ impl From<Task> for domain::Task {
|
||||||
fn from(repo: Task) -> Self {
|
fn from(repo: Task) -> Self {
|
||||||
domain::Task {
|
domain::Task {
|
||||||
name: repo.name,
|
name: repo.name,
|
||||||
link: repo.link,
|
|
||||||
group: repo.group,
|
group: repo.group,
|
||||||
|
link: repo.link,
|
||||||
|
path: repo.path.map(PathBuf::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,12 +105,16 @@ impl Repository for FsRepo {
|
||||||
task.name = name;
|
task.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(group) = update_data.group {
|
||||||
|
task.group = group;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(link) = update_data.link {
|
if let Some(link) = update_data.link {
|
||||||
task.link = link;
|
task.link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(group) = update_data.group {
|
if let Some(path) = update_data.path {
|
||||||
task.group = group;
|
task.path = path.and_then(|p| p.into_os_string().into_string().ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_task = task.clone();
|
let new_task = task.clone();
|
||||||
|
@ -120,8 +127,11 @@ impl Repository for FsRepo {
|
||||||
fn insert_task(&self, insert_data: InsertTaskData) -> Result<domain::Task, Error> {
|
fn insert_task(&self, insert_data: InsertTaskData) -> Result<domain::Task, Error> {
|
||||||
let new_task = Task {
|
let new_task = Task {
|
||||||
name: insert_data.name,
|
name: insert_data.name,
|
||||||
link: insert_data.link,
|
|
||||||
group: insert_data.group,
|
group: insert_data.group,
|
||||||
|
link: insert_data.link,
|
||||||
|
path: insert_data
|
||||||
|
.path
|
||||||
|
.and_then(|p| p.into_os_string().into_string().ok()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tasks = self.get_tasks_impl()?;
|
let mut tasks = self.get_tasks_impl()?;
|
||||||
|
|
Loading…
Reference in a new issue