Skip to content

Commit

Permalink
refactor: Use io::Result instead of anyhow in gen mod
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Dec 22, 2023
1 parent f318b52 commit 3e93f06
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/gen/bash.rs
Original file line number Diff line number Diff line change
@@ -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"));
Expand Down
4 changes: 1 addition & 3 deletions src/gen/json.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/gen/nu.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 1 addition & 3 deletions src/gen/zsh.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{fs, path::Path};

use anyhow::Result;

use crate::gen::{
util::{self, Output},
CommandInfo,
Expand Down Expand Up @@ -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"));
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// use assert_cmd::prelude::*;
use std::{
env, fs,
path::PathBuf,
Expand Down

0 comments on commit 3e93f06

Please sign in to comment.