ux improvements
- rename group to project - rename path to dir_path - cli/show: add project to the print part - cli/show: improve print part error message Closes #25
This commit is contained in:
parent
9837857081
commit
18004c24d0
9 changed files with 57 additions and 45 deletions
|
@ -52,8 +52,8 @@ pub enum SubCommand {
|
||||||
|
|
||||||
pub fn print_task_detail(task: &domain::Task) {
|
pub fn print_task_detail(task: &domain::Task) {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
if let Some(group) = task.group.as_ref() {
|
if let Some(project) = task.project.as_ref() {
|
||||||
print!("[{}]: ", group);
|
print!("[{}]: ", project);
|
||||||
}
|
}
|
||||||
println!("{}", task.name);
|
println!("{}", task.name);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ pub fn print_task_detail(task: &domain::Task) {
|
||||||
println!(" link: {}", link);
|
println!(" link: {}", link);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = task.path.as_ref() {
|
if let Some(dir_path) = task.dir_path.as_ref() {
|
||||||
println!(" path: {}", path.to_string_lossy());
|
println!(" path: {}", dir_path.to_string_lossy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ use crate::{
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
group: Option<String>,
|
project: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
link: Option<String>,
|
link: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long = "dir")]
|
||||||
path: Option<String>,
|
dir_path: Option<String>,
|
||||||
|
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,12 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
let res = repo.insert_task(repo::InsertTaskData {
|
let res = repo.insert_task(repo::InsertTaskData {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
link: args.link,
|
link: args.link,
|
||||||
group: args.group,
|
project: args.project,
|
||||||
path: args.path.map(std::fs::canonicalize).transpose().unwrap(),
|
dir_path: args
|
||||||
|
.dir_path
|
||||||
|
.map(std::fs::canonicalize)
|
||||||
|
.transpose()
|
||||||
|
.unwrap(),
|
||||||
index: None,
|
index: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -24,19 +24,19 @@ pub struct Args {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
group: Option<String>,
|
project: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
no_group: bool,
|
no_project: bool,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
link: Option<String>,
|
link: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
no_link: bool,
|
no_link: bool,
|
||||||
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long = "dir")]
|
||||||
path: Option<PathBuf>,
|
dir_path: Option<PathBuf>,
|
||||||
#[clap(long)]
|
#[clap(long = "no-dir")]
|
||||||
no_path: bool,
|
no_dir_path: bool,
|
||||||
|
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,15 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
args.idx,
|
args.idx,
|
||||||
repo::UpdateTaskData {
|
repo::UpdateTaskData {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
group: args.no_group.then(|| None).or_else(|| args.group.map(Some)),
|
project: args
|
||||||
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
.no_project
|
||||||
path: args
|
|
||||||
.no_path
|
|
||||||
.then(|| None)
|
.then(|| None)
|
||||||
.or_else(|| args.path.map(std::fs::canonicalize).transpose().ok()),
|
.or_else(|| args.project.map(Some)),
|
||||||
|
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
||||||
|
dir_path: args
|
||||||
|
.no_dir_path
|
||||||
|
.then(|| None)
|
||||||
|
.or_else(|| args.dir_path.map(std::fs::canonicalize).transpose().ok()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
match res {
|
match res {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::repo::Repository;
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
groups: Vec<String>,
|
projects: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(repo: impl Repository, args: Args) {
|
pub fn execute(repo: impl Repository, args: Args) {
|
||||||
|
@ -34,8 +34,8 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let groups = args
|
let projects = args
|
||||||
.groups
|
.projects
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|g| match g.as_str() {
|
.map(|g| match g.as_str() {
|
||||||
"-" => None,
|
"-" => None,
|
||||||
|
@ -46,7 +46,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
let filtered_tasks = tasks
|
let filtered_tasks = tasks
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, t)| groups.is_empty() || groups.contains(&t.group));
|
.filter(|(_, t)| projects.is_empty() || projects.contains(&t.project));
|
||||||
|
|
||||||
for (i, task) in filtered_tasks {
|
for (i, task) in filtered_tasks {
|
||||||
let idx = i + 1;
|
let idx = i + 1;
|
||||||
|
@ -57,8 +57,8 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("{}. ", idx);
|
print!("{}. ", idx);
|
||||||
if let Some(group) = task.group.as_ref() {
|
if let Some(project) = task.project.as_ref() {
|
||||||
print!("[{}]: ", group);
|
print!("[{}]: ", project);
|
||||||
}
|
}
|
||||||
print!("{}", task.name);
|
print!("{}", task.name);
|
||||||
if task.link.is_some() {
|
if task.link.is_some() {
|
||||||
|
|
|
@ -74,9 +74,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,
|
||||||
group: target.group,
|
project: target.project,
|
||||||
link: target.link,
|
link: target.link,
|
||||||
path: target.path,
|
dir_path: target.dir_path,
|
||||||
});
|
});
|
||||||
match res {
|
match res {
|
||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
|
|
|
@ -24,7 +24,8 @@ pub struct Args {
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone)]
|
#[derive(clap::ValueEnum, Clone)]
|
||||||
enum PrintPart {
|
enum PrintPart {
|
||||||
Path,
|
Project,
|
||||||
|
DirPath,
|
||||||
Link,
|
Link,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +34,10 @@ impl std::str::FromStr for PrintPart {
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s {
|
match s {
|
||||||
"path" => Ok(PrintPart::Path),
|
"project" => Ok(PrintPart::Project),
|
||||||
|
"dir" => Ok(PrintPart::DirPath),
|
||||||
"link" => Ok(PrintPart::Link),
|
"link" => Ok(PrintPart::Link),
|
||||||
_ => Err(r#"You can display only "path" or "link""#),
|
_ => Err("Available parts: dir, link, project"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,10 +58,13 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
println!("Information about your current task:");
|
println!("Information about your current task:");
|
||||||
print_task_detail(&task);
|
print_task_detail(&task);
|
||||||
}
|
}
|
||||||
Some(PrintPart::Path) => {
|
Some(PrintPart::Project) => {
|
||||||
|
println!("{}", task.project.unwrap_or_else(|| String::from('-')))
|
||||||
|
}
|
||||||
|
Some(PrintPart::DirPath) => {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
task.path
|
task.dir_path
|
||||||
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
|
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,9 +19,9 @@ pub type TaskId = usize;
|
||||||
|
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub group: Option<String>,
|
pub project: Option<String>,
|
||||||
pub link: Option<String>,
|
pub link: Option<String>,
|
||||||
pub path: Option<PathBuf>,
|
pub dir_path: Option<PathBuf>,
|
||||||
// created_at
|
// created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,17 +40,17 @@ impl std::error::Error for Error {}
|
||||||
|
|
||||||
pub struct InsertTaskData {
|
pub struct InsertTaskData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub group: Option<String>,
|
pub project: Option<String>,
|
||||||
pub link: Option<String>,
|
pub link: Option<String>,
|
||||||
pub path: Option<PathBuf>,
|
pub dir_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 group: Option<Option<String>>,
|
pub project: Option<Option<String>>,
|
||||||
pub link: Option<Option<String>>,
|
pub link: Option<Option<String>>,
|
||||||
pub path: Option<Option<PathBuf>>,
|
pub dir_path: Option<Option<PathBuf>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Repository {
|
pub trait Repository {
|
||||||
|
|
|
@ -36,9 +36,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,
|
||||||
group: repo.group,
|
project: repo.group,
|
||||||
link: repo.link,
|
link: repo.link,
|
||||||
path: repo.path.map(PathBuf::from),
|
dir_path: repo.path.map(PathBuf::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ impl Repository for FsRepo {
|
||||||
task.name = name;
|
task.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(group) = update_data.group {
|
if let Some(group) = update_data.project {
|
||||||
task.group = group;
|
task.group = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ impl Repository for FsRepo {
|
||||||
task.link = link;
|
task.link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = update_data.path {
|
if let Some(path) = update_data.dir_path {
|
||||||
task.path = path.and_then(|p| p.into_os_string().into_string().ok());
|
task.path = path.and_then(|p| p.into_os_string().into_string().ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,10 +142,10 @@ 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,
|
||||||
group: insert_data.group,
|
group: insert_data.project,
|
||||||
link: insert_data.link,
|
link: insert_data.link,
|
||||||
path: insert_data
|
path: insert_data
|
||||||
.path
|
.dir_path
|
||||||
.and_then(|p| p.into_os_string().into_string().ok()),
|
.and_then(|p| p.into_os_string().into_string().ok()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue