mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
introduce use env_logger
related to https://github.com/denisidoro/navi/issues/576 For the following config cheats: paths: - C:\\Users\\Administrator\\AppData\\Roaming\\navi\\cheat - C:\\Users\\Administrator\\AppData\\Roaming\\navi\\cheat navi now gets incorrect paths on Windows, since the seperator `:` for path join is a valid component. [2023-05-12T08:58:26Z DEBUG navi::commands::core] Filesystem( Some( "C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat:C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat", ), ) [2023-05-12T08:58:28Z DEBUG navi::filesystem] filesystem::Fetcher = Fetcher { path: Some( "C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat:C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat", ), files: RefCell { value: [], }, }
This commit is contained in:
parent
eb9ad7c09f
commit
196872b109
12 changed files with 54 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
navi.log
|
||||
|
|
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -260,6 +260,16 @@ version = "1.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
|
||||
dependencies = [
|
||||
"humantime",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.0"
|
||||
|
@ -344,6 +354,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
|
@ -412,9 +428,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
@ -456,8 +472,10 @@ dependencies = [
|
|||
"dns_common",
|
||||
"dns_common_derive",
|
||||
"edit",
|
||||
"env_logger",
|
||||
"etcetera",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"regex",
|
||||
"remove_dir_all 0.8.2",
|
||||
"serde",
|
||||
|
|
|
@ -36,6 +36,8 @@ serde_yaml = "0.9.21"
|
|||
dns_common_derive = { version = "0.2.1" }
|
||||
dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] }
|
||||
unicode-width = "0.1.10"
|
||||
log = "0.4"
|
||||
env_logger = { version = "0.10", default_features = false, features = ["humantime"] }
|
||||
|
||||
[lib]
|
||||
name = "navi"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
extern crate navi;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
@ -25,5 +24,18 @@ impl FileAnIssue {
|
|||
}
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
navi::handle().map_err(|e| FileAnIssue::new(e).into())
|
||||
init_logger()?;
|
||||
navi::handle().map_err(|e| {
|
||||
log::error!("{e:?}");
|
||||
FileAnIssue::new(e).into()
|
||||
})
|
||||
}
|
||||
|
||||
fn init_logger() -> anyhow::Result<()> {
|
||||
let file = std::fs::File::create("navi.log")?;
|
||||
env_logger::builder()
|
||||
.target(env_logger::Target::Pipe(Box::new(file)))
|
||||
.init();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -44,7 +44,9 @@ pub fn init(fetcher: Box<dyn Fetcher>) -> Result<()> {
|
|||
}
|
||||
|
||||
pub fn get_fetcher() -> Result<Box<dyn Fetcher>> {
|
||||
match CONFIG.source() {
|
||||
let source = CONFIG.source();
|
||||
log::debug!("{source:#?}");
|
||||
match source {
|
||||
Source::Cheats(query) => {
|
||||
let lines = cheatsh::call(&query)?;
|
||||
let fetcher = Box::new(StaticFetcher::new(lines));
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::prelude::*;
|
|||
pub fn handle() -> Result<()> {
|
||||
use crate::config::Command::*;
|
||||
|
||||
log::debug!("CONFIG = {:#?}", &*CONFIG);
|
||||
match CONFIG.cmd() {
|
||||
None => commands::core::main(),
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ pub enum Command {
|
|||
Info(commands::info::Input),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Source {
|
||||
Filesystem(Option<String>),
|
||||
Tldr(String),
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::env_var;
|
|||
use crate::finder::FinderChoice;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EnvConfig {
|
||||
pub config_yaml: Option<String>,
|
||||
pub config_path: Option<String>,
|
||||
|
|
|
@ -12,6 +12,7 @@ use yaml::YamlConfig;
|
|||
lazy_static! {
|
||||
pub static ref CONFIG: Config = Config::new();
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
yaml: YamlConfig,
|
||||
clap: ClapConfig,
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::prelude::*;
|
|||
use crossterm::style::Color as TerminalColor;
|
||||
use serde::de;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Color(#[serde(deserialize_with = "color_deserialize")] TerminalColor);
|
||||
|
||||
impl Color {
|
||||
|
@ -24,7 +24,7 @@ where
|
|||
.map_err(|_| de::Error::custom(format!("Failed to deserialize color: {s}")))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct ColorWidth {
|
||||
pub color: Color,
|
||||
|
@ -32,7 +32,7 @@ pub struct ColorWidth {
|
|||
pub min_width: u16,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Style {
|
||||
pub tag: ColorWidth,
|
||||
|
@ -40,7 +40,7 @@ pub struct Style {
|
|||
pub snippet: ColorWidth,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Finder {
|
||||
#[serde(deserialize_with = "finder_deserialize")]
|
||||
|
@ -58,27 +58,27 @@ where
|
|||
.map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {s}")))
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Cheats {
|
||||
pub path: Option<String>,
|
||||
pub paths: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Search {
|
||||
pub tags: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct Shell {
|
||||
pub command: String,
|
||||
pub finder_command: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
#[serde(default)]
|
||||
pub struct YamlConfig {
|
||||
pub style: Style,
|
||||
|
|
|
@ -125,6 +125,7 @@ fn interpolate_paths(paths: String) -> String {
|
|||
newtext
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fetcher {
|
||||
path: Option<String>,
|
||||
files: RefCell<Vec<String>>,
|
||||
|
@ -180,6 +181,7 @@ impl fetcher::Fetcher for Fetcher {
|
|||
}
|
||||
}
|
||||
|
||||
log::debug!("filesystem::Fetcher = {self:#?}");
|
||||
Ok(found_something)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
// #[macro_use]
|
||||
// extern crate anyhow;
|
||||
|
||||
mod clients;
|
||||
mod commands;
|
||||
|
|
Loading…
Reference in a new issue