fixed bookmarks completions, light refactoring
This commit is contained in:
+3
-7
@@ -79,7 +79,7 @@ pub struct StackArgs {
|
|||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
pub enum StackAction {
|
pub enum StackAction {
|
||||||
/// clear stack
|
/// clear stack
|
||||||
clear(EmptyArgs),
|
clear,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Args)]
|
#[derive(Debug, Clone, Args)]
|
||||||
@@ -95,7 +95,7 @@ pub struct BookmarkArgs {
|
|||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
pub enum BookmarkAction {
|
pub enum BookmarkAction {
|
||||||
/// list all bookmarks
|
/// list all bookmarks
|
||||||
list(EmptyArgs),
|
list,
|
||||||
|
|
||||||
/// add a bookmark with `book add <name> <path>`
|
/// add a bookmark with `book add <name> <path>`
|
||||||
add(BookmarkSubArgs),
|
add(BookmarkSubArgs),
|
||||||
@@ -104,7 +104,7 @@ pub enum BookmarkAction {
|
|||||||
remove(BookmarkSubArgs),
|
remove(BookmarkSubArgs),
|
||||||
|
|
||||||
/// get bookmarknames for shell completions
|
/// get bookmarknames for shell completions
|
||||||
completions(EmptyArgs),
|
completions,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Args)]
|
#[derive(Debug, Clone, Args)]
|
||||||
@@ -123,7 +123,3 @@ pub struct ConfigArgs {
|
|||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub convert: Option<bool>,
|
pub convert: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// empty struct for subcommands with no arguments
|
|
||||||
#[derive(Debug, Clone, Args)]
|
|
||||||
pub struct EmptyArgs {}
|
|
||||||
|
|||||||
+3
-4
@@ -75,7 +75,6 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
output.push_error(&res.unwrap_err().to_string());
|
output.push_error(&res.unwrap_err().to_string());
|
||||||
output.push_command(&"false".to_owned());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print output and command
|
// print output and command
|
||||||
@@ -146,7 +145,7 @@ fn handle_pop(args: &PopArgs, config: &Config, stack: &mut Stack, output: &mut O
|
|||||||
fn handle_stack(args: &StackArgs, config: &Config, stack: &mut Stack, output: &mut Output) -> Result<()> {
|
fn handle_stack(args: &StackArgs, config: &Config, stack: &mut Stack, output: &mut Output) -> Result<()> {
|
||||||
if args.stack_action.is_some() {
|
if args.stack_action.is_some() {
|
||||||
match args.stack_action.clone().unwrap() {
|
match args.stack_action.clone().unwrap() {
|
||||||
StackAction::clear(_) => {
|
StackAction::clear => {
|
||||||
stack.clear_stack()?;
|
stack.clear_stack()?;
|
||||||
output.push_info(&"stack cleared.".to_owned());
|
output.push_info(&"stack cleared.".to_owned());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -161,10 +160,10 @@ fn handle_stack(args: &StackArgs, config: &Config, stack: &mut Stack, output: &m
|
|||||||
fn handle_bookmark(args: &BookmarkArgs, config: &Config, bookmarks: &mut Bookmarks, stack: &mut Stack, output: &mut Output) -> Result<()> {
|
fn handle_bookmark(args: &BookmarkArgs, config: &Config, bookmarks: &mut Bookmarks, stack: &mut Stack, output: &mut Output) -> Result<()> {
|
||||||
if let Some(action) = &args.bookmark_action {
|
if let Some(action) = &args.bookmark_action {
|
||||||
match action {
|
match action {
|
||||||
BookmarkAction::list(_) => list_bookmarks(config, bookmarks, output)?,
|
BookmarkAction::list => list_bookmarks(config, bookmarks, output)?,
|
||||||
BookmarkAction::add(args) => add_bookmarks(args, config, bookmarks, output)?,
|
BookmarkAction::add(args) => add_bookmarks(args, config, bookmarks, output)?,
|
||||||
BookmarkAction::remove(args) => remove_bookmarks(args, config, bookmarks, output)?,
|
BookmarkAction::remove(args) => remove_bookmarks(args, config, bookmarks, output)?,
|
||||||
BookmarkAction::completions(_) => println!("echo '{}'", bookmarks.get_bookmarknames()),
|
BookmarkAction::completions => println!("echo '{}'", bookmarks.get_bookmarknames()),
|
||||||
};
|
};
|
||||||
} else if args.name.is_some() { // handle `change to bookmark`
|
} else if args.name.is_some() { // handle `change to bookmark`
|
||||||
let path = bookmarks.get_path_by_name(args.name.as_ref().unwrap())?;
|
let path = bookmarks.get_path_by_name(args.name.as_ref().unwrap())?;
|
||||||
|
|||||||
+7
-1
@@ -1,6 +1,7 @@
|
|||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
use clap::builder::EnumValueParser;
|
use clap::builder::EnumValueParser;
|
||||||
|
use config_parser::RESET_SEQ;
|
||||||
|
|
||||||
use super::config::*;
|
use super::config::*;
|
||||||
|
|
||||||
@@ -58,13 +59,18 @@ impl Output {
|
|||||||
|
|
||||||
/// format and print styled output
|
/// format and print styled output
|
||||||
/// NOTE - this will execute any commands held by `command`
|
/// NOTE - this will execute any commands held by `command`
|
||||||
pub fn print_output(&self, config: Option<&Config>) {
|
pub fn print_output(&mut self, config: Option<&Config>) {
|
||||||
let default = Config::default();
|
let default = Config::default();
|
||||||
let config = if let Some(value) = config {
|
let config = if let Some(value) = config {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
&default
|
&default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !self.error.is_empty() {
|
||||||
|
self.push_command(&"false".to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
let mut info: String = self.info.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
let mut info: String = self.info.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||||
let mut warning: String = self.warning.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
let mut warning: String = self.warning.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||||
let mut error: String = self.error.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
let mut error: String = self.error.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||||
|
|||||||
Reference in New Issue
Block a user