Skip to content

Commit 656f11b

Browse files
committed
move to color_eyre
1 parent 7ce33d9 commit 656f11b

File tree

4 files changed

+235
-15
lines changed

4 files changed

+235
-15
lines changed

Cargo.lock

Lines changed: 221 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ description = "Utility (and mini-language) for shell completions (\"tab completi
66
license = "MIT"
77

88
[dependencies]
9-
anyhow = "1.0.72"
109
clap = { version = "4.5.17", features = ["derive"] }
10+
color-eyre = "0.6.3"
1111
serde = { version = "1.0", features = ["derive"] }
1212
serde_json = "1.0"
1313
shell-words = "1.1.0"

src/app/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod config_finder;
44
mod shell_tokenizer;
55

66
/// Main app functionality
7-
use anyhow::Context;
7+
use color_eyre::eyre::{Context, Result, eyre};
88
use std::io::Read;
99

1010
use crate::{
@@ -13,7 +13,7 @@ use crate::{
1313
lang,
1414
};
1515

16-
fn print_options(config_filename: &str, tokens: &[String], last_token: &str) -> anyhow::Result<()> {
16+
fn print_options(config_filename: &str, tokens: &[String], last_token: &str) -> Result<()> {
1717
let config =
1818
config::TabryConf::from_file(config_filename).with_context(|| "invalid config file")?;
1919
let result =
@@ -44,10 +44,11 @@ fn print_options(config_filename: &str, tokens: &[String], last_token: &str) ->
4444
}
4545

4646
// This runs using the filename plus 2nd arg as compline (shellsplits ARGV[2])
47-
pub fn run_as_compline(compline: &str, comppoint: &str) -> anyhow::Result<()> {
48-
let comppoint = comppoint.parse::<usize>()?;
47+
pub fn run_as_compline(compline: &str, comppoint: &str) -> Result<()> {
48+
let comppoint = comppoint.parse::<usize>().wrap_err_with(|| eyre!("Invalid compoint: {}", comppoint))?;
49+
50+
let tokenized_result = shell_tokenizer::split_with_comppoint(compline, comppoint).wrap_err_with(|| eyre!("Failed to split compline {} on comppoint {}", compline, comppoint))?;
4951

50-
let tokenized_result = shell_tokenizer::split_with_comppoint(compline, comppoint)?;
5152
let args = tokenized_result.arguments;
5253
let last_arg = tokenized_result.last_argument;
5354

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{Parser, Subcommand};
2+
use color_eyre::eyre::Result;
23

34
#[derive(Parser)]
45
#[command(name = "tabry")]
@@ -69,16 +70,20 @@ enum Subcommands {
6970
},
7071
}
7172

72-
fn main() {
73+
fn main() -> Result<()> {
74+
color_eyre::install()?;
75+
7376
use Subcommands::*;
7477
use tabry::app::*;
7578
let cli = Cli::parse();
7679
match cli.command {
77-
Complete { compline, comppoint } => run_as_compline(&compline, &comppoint).unwrap(),
80+
Complete { compline, comppoint } => run_as_compline(&compline, &comppoint)?,
7881
Compile => compile(),
7982
Commands => commands(),
8083
Bash { import_path, no_auto } => bash(import_path.as_deref(), no_auto),
8184
Zsh { import_path, no_auto } => zsh(import_path.as_deref(), no_auto),
8285
Fish { import_path, no_auto } => fish(import_path.as_deref(), no_auto),
8386
}
87+
88+
Ok(())
8489
}

0 commit comments

Comments
 (0)