From 3e93f06f3753113664329e85a20b16ee9e39b79a Mon Sep 17 00:00:00 2001 From: ysthakur <45539777+ysthakur@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:48:24 -0500 Subject: [PATCH] refactor: Use io::Result instead of anyhow in gen mod --- src/gen/bash.rs | 4 +--- src/gen/json.rs | 4 +--- src/gen/nu.rs | 4 +--- src/gen/zsh.rs | 4 +--- src/main.rs | 9 +++++---- tests/integration_tests.rs | 1 - 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/gen/bash.rs b/src/gen/bash.rs index c41ee9a..b27a7ff 100644 --- a/src/gen/bash.rs +++ b/src/gen/bash.rs @@ -1,11 +1,9 @@ use std::{fs, path::Path}; -use anyhow::Result; - use crate::gen::{util::Output, CommandInfo}; /// Generate a completion file for Bash -pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> Result<()> { +pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> std::io::Result<()> { let comp_name = format!("_comp_cmd_{}", cmd.name); let mut out = Output::new(String::from("\t")); diff --git a/src/gen/json.rs b/src/gen/json.rs index 81ee091..9d84567 100644 --- a/src/gen/json.rs +++ b/src/gen/json.rs @@ -1,13 +1,11 @@ use std::{fs, path::Path}; -use anyhow::Result; - use crate::gen::{util::Output, CommandInfo}; /// Generate JSON representing the parsed options /// /// This should probably use a real JSON library but whatever -pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> Result<()> { +pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> std::io::Result<()> { let mut res = Output::new(String::from(" ")); res.writeln("{"); res.indent(); diff --git a/src/gen/nu.rs b/src/gen/nu.rs index 4927326..cd0169d 100644 --- a/src/gen/nu.rs +++ b/src/gen/nu.rs @@ -1,11 +1,9 @@ use std::{fs, path::Path}; -use anyhow::Result; - use crate::gen::{util::Output, CommandInfo}; /// Generate completions for Nushell -pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> Result<()> { +pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> std::io::Result<()> { let mut res = Output::new(String::from(" ")); generate_cmd(&cmd.name, cmd, &mut res, true); fs::write( diff --git a/src/gen/zsh.rs b/src/gen/zsh.rs index 5fc1375..7d47707 100644 --- a/src/gen/zsh.rs +++ b/src/gen/zsh.rs @@ -1,7 +1,5 @@ use std::{fs, path::Path}; -use anyhow::Result; - use crate::gen::{ util::{self, Output}, CommandInfo, @@ -38,7 +36,7 @@ use crate::gen::{ /// '-b[Make new branch]' /// } /// ``` -pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> Result<()> { +pub fn generate(cmd: &CommandInfo, out_dir: &Path) -> std::io::Result<()> { // TODO make option to not overwrite file let comp_name = format!("_{}", cmd.name); let mut res = Output::new(String::from("\t")); diff --git a/src/main.rs b/src/main.rs index 3ccb328..35b81c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,11 +83,12 @@ fn gen_shell( out_dir: &Path, ) -> Result<()> { match shell { - Shell::Zsh => gen::zsh::generate(parsed, out_dir), - Shell::Json => gen::json::generate(parsed, out_dir), - Shell::Bash => gen::bash::generate(parsed, out_dir), - Shell::Nu => gen::nu::generate(parsed, out_dir), + Shell::Zsh => gen::zsh::generate(parsed, out_dir)?, + Shell::Json => gen::json::generate(parsed, out_dir)?, + Shell::Bash => gen::bash::generate(parsed, out_dir)?, + Shell::Nu => gen::nu::generate(parsed, out_dir)?, } + Ok(()) } fn main() -> Result<()> { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 4bcaf8e..aaad44d 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,4 +1,3 @@ -// use assert_cmd::prelude::*; use std::{ env, fs, path::PathBuf,