Skip to content

Commit

Permalink
wip: replace simple_error with anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed May 2, 2024
1 parent 88bfe4f commit 4ee77f6
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 462 deletions.
954 changes: 517 additions & 437 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ repository = "https://github.com/cilki/wsm/"
[dependencies]
toml = "0"
serde = { version = "1", features = ["derive"] }
git-repository = "0"
git-repository = { version = "0", optional = true }
walkdir = "2"
cmd_lib = "1.3.0"
regex = "1"
log = "0.4.17"
env_logger = "0.10.0"
simple-error = "0.2.3"
pico-args = "0.5.0"
sha2 = "0.10.6"
anyhow = "1.0.82"

[features]
git_oxide = ["dep:git-repository"]
4 changes: 2 additions & 2 deletions src/api/github.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api::Provider;
use crate::Provider;
use std::error::Error;
use anyhow::Result;
use std::fmt;

pub struct GithubProvider {
Expand All @@ -14,7 +14,7 @@ impl fmt::Display for GithubProvider {
}

impl Provider for GithubProvider {
fn list_repo_paths(&self) -> Result<Vec<String>, Box<dyn Error>> {
fn list_repo_paths(&self) -> Result<Vec<String>> {
let mut paths: Vec<String> = Vec::new();

/*loop {
Expand Down
4 changes: 2 additions & 2 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::error::Error;
use anyhow::Result;
use std::fmt::Display;

//pub mod github;
//pub mod gitlab;

pub trait Provider: Display {
/// List all repository paths available to the provider.
fn list_repo_paths(&self) -> Result<Vec<String>, Box<dyn Error>>;
fn list_repo_paths(&self) -> Result<Vec<String>>;
}
4 changes: 2 additions & 2 deletions src/cmd/drop.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::cmd::RepoPattern;
use crate::Config;
use anyhow::Result;
use cmd_lib::*;
use log::debug;
use std::error::Error;

/// Drop one or more repositories from the workspace
pub fn run_drop(config: &Config, path: Option<String>) -> Result<(), Box<dyn Error>> {
pub fn run_drop(config: &Config, path: Option<String>) -> Result<()> {
debug!("Drop requested for: {:?}", &path);

let repos = match path {
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::bail;
use anyhow::Result;
use regex::Regex;
use simple_error::bail;
use std::error::Error;

pub mod drop;
pub mod open;
Expand All @@ -17,7 +17,7 @@ pub struct RepoPattern {
}

impl RepoPattern {
pub fn parse(path: &str) -> Result<Self, Box<dyn Error>> {
pub fn parse(path: &str) -> Result<Self> {
match Regex::new(r"^([^/]+:)?(.*)$")?.captures(path) {
Some(captures) => Ok(Self {
workspace: captures
Expand All @@ -43,10 +43,10 @@ impl RepoPattern {
#[cfg(test)]
mod test_repo_pattern {
use super::RepoPattern;
use std::error::Error;
use anyhow::Result;

#[test]
fn test_parse() -> Result<(), Box<dyn Error>> {
fn test_parse() -> Result<()> {
assert_eq!(
RepoPattern::parse("workspace12:remote1/abc/123")?,
RepoPattern {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/open.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::cmd::RepoPattern;
use crate::Config;
use anyhow::Result;
use cmd_lib::*;
use log::debug;
use std::error::Error;

/// Open one or more repositories in the workspace
pub fn run_open(config: &Config, path: Option<String>) -> Result<(), Box<dyn Error>> {
pub fn run_open(config: &Config, path: Option<String>) -> Result<()> {
debug!("Open requested for: {:?}", &path);

// Check the cache first
if let Some(cache) = &config.cache {

}
if let Some(cache) = &config.cache {}

let repos = match path {
Some(p) => config.resolve_local(&RepoPattern::parse(&p)?), // TODO remote
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cmd::RepoPattern;
use anyhow::Result;
use cmd_lib::run_fun;
use log::debug;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -55,7 +56,7 @@ impl Config {
}

/// Recursively find git repositories.
fn find_git_dir(path: &str) -> Result<Vec<PathBuf>, Box<dyn Error>> {
fn find_git_dir(path: &str) -> Result<Vec<PathBuf>> {
debug!("Searching for git repositories in: {}", path);
let mut found: Vec<PathBuf> = Vec::new();

Expand Down Expand Up @@ -118,7 +119,7 @@ pub struct Cache {

impl Cache {
/// Move the given repository into the cache.
pub fn cache(&self, repo_path: String) -> Result<(), Box<dyn Error>> {
pub fn cache(&self, repo_path: String) -> Result<()> {
// Make sure the cache directory exists first
std::fs::create_dir_all(&self.cache)?;

Expand All @@ -135,7 +136,7 @@ impl Cache {
Ok(())
}

pub fn uncache(&self, repo_path: String) -> Result<(), Box<dyn Error>> {
pub fn uncache(&self, repo_path: String) -> Result<()> {
let source = self.compute_cache_key(&repo_path);
run_fun!(git clone $source $repo_path)?;
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use log::debug;
use std::error::Error;
use wsm::Config;

fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<()> {
// Initialize logging
env_logger::init();

Expand Down Expand Up @@ -41,11 +41,11 @@ fn main() -> Result<(), Box<dyn Error>> {
}

/// Output dynamic completions for bash
fn complete_bash() -> Result<(), Box<dyn Error>> {
fn complete_bash() -> Result<()> {
todo!()
}

/// Output dynamic completions for fish
fn complete_fish() -> Result<(), Box<dyn Error>> {
fn complete_fish() -> Result<()> {
todo!()
}

0 comments on commit 4ee77f6

Please sign in to comment.