Skip to content

Commit

Permalink
move to color_eyre
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbattaglia committed Sep 19, 2024
1 parent 7ce33d9 commit 656f11b
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 15 deletions.
228 changes: 221 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ description = "Utility (and mini-language) for shell completions (\"tab completi
license = "MIT"

[dependencies]
anyhow = "1.0.72"
clap = { version = "4.5.17", features = ["derive"] }
color-eyre = "0.6.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shell-words = "1.1.0"
Expand Down
11 changes: 6 additions & 5 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod config_finder;
mod shell_tokenizer;

/// Main app functionality
use anyhow::Context;
use color_eyre::eyre::{Context, Result, eyre};
use std::io::Read;

use crate::{
Expand All @@ -13,7 +13,7 @@ use crate::{
lang,
};

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

// This runs using the filename plus 2nd arg as compline (shellsplits ARGV[2])
pub fn run_as_compline(compline: &str, comppoint: &str) -> anyhow::Result<()> {
let comppoint = comppoint.parse::<usize>()?;
pub fn run_as_compline(compline: &str, comppoint: &str) -> Result<()> {
let comppoint = comppoint.parse::<usize>().wrap_err_with(|| eyre!("Invalid compoint: {}", comppoint))?;

let tokenized_result = shell_tokenizer::split_with_comppoint(compline, comppoint).wrap_err_with(|| eyre!("Failed to split compline {} on comppoint {}", compline, comppoint))?;

let tokenized_result = shell_tokenizer::split_with_comppoint(compline, comppoint)?;
let args = tokenized_result.arguments;
let last_arg = tokenized_result.last_argument;

Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{Parser, Subcommand};
use color_eyre::eyre::Result;

#[derive(Parser)]
#[command(name = "tabry")]
Expand Down Expand Up @@ -69,16 +70,20 @@ enum Subcommands {
},
}

fn main() {
fn main() -> Result<()> {
color_eyre::install()?;

use Subcommands::*;
use tabry::app::*;
let cli = Cli::parse();
match cli.command {
Complete { compline, comppoint } => run_as_compline(&compline, &comppoint).unwrap(),
Complete { compline, comppoint } => run_as_compline(&compline, &comppoint)?,
Compile => compile(),
Commands => commands(),
Bash { import_path, no_auto } => bash(import_path.as_deref(), no_auto),
Zsh { import_path, no_auto } => zsh(import_path.as_deref(), no_auto),
Fish { import_path, no_auto } => fish(import_path.as_deref(), no_auto),
}

Ok(())
}

0 comments on commit 656f11b

Please sign in to comment.