1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 03:12:25 +01:00

Strip dependencies of bat-as-a-library

This commit is contained in:
David Tolnay
2020-03-30 09:43:13 -07:00
committed by David Peter
parent e7e1967bb0
commit 570805bc98
13 changed files with 100 additions and 77 deletions

View File

@@ -9,13 +9,9 @@ use crate::{
config::{get_args_from_config_file, get_args_from_env_var},
};
use clap::ArgMatches;
use wild;
use console::Term;
#[cfg(windows)]
use ansi_term;
use bat::{
config::{
Config, HighlightedLineRanges, InputFile, LineRange, LineRanges, MappingTarget, OutputWrap,

View File

@@ -1,4 +1,4 @@
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
use std::path::Path;
pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {

View File

@@ -4,8 +4,6 @@ use std::fs;
use std::io::{self, Write};
use std::path::PathBuf;
use shell_words;
use crate::directories::PROJECT_DIRS;
pub fn config_file() -> PathBuf {

View File

@@ -1,7 +1,6 @@
use std::env;
use std::path::{Path, PathBuf};
use dirs;
use lazy_static::lazy_static;
/// Wrapper for 'dirs' that treats MacOS more like Linux, by following the XDG specification.

View File

@@ -1,11 +1,6 @@
// `error_chain!` can recurse deeply
#![recursion_limit = "1024"]
#[macro_use]
extern crate clap;
extern crate dirs as dirs_rs;
mod app;
mod assets;
mod clap_app;

View File

@@ -2,20 +2,20 @@ use error_chain::error_chain;
error_chain! {
foreign_links {
Clap(::clap::Error);
Io(::std::io::Error);
SyntectError(::syntect::LoadingError);
ParseIntError(::std::num::ParseIntError);
GlobParsingError(::globset::Error);
Clap(clap::Error);
Io(std::io::Error);
SyntectError(syntect::LoadingError);
ParseIntError(std::num::ParseIntError);
GlobParsingError(globset::Error);
}
}
pub fn default_error_handler(error: &Error) {
match error {
Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
if io_error.kind() == std::io::ErrorKind::BrokenPipe =>
{
::std::process::exit(0);
std::process::exit(0);
}
_ => {
use ansi_term::Colour::Red;
@@ -23,3 +23,36 @@ pub fn default_error_handler(error: &Error) {
}
};
}
// Mock out a type for clap::Error if we aren't pulling in a dependency on clap.
//
// This can be removed after migrating away from error_chain to some modern
// derive-based error library such as thiserror, in favor of:
//
// #[derive(Error)]
// pub enum Error {
// #[cfg(feature = "application")]
// Clap(clap::Error),
// ...
// }
//
#[cfg(not(feature = "application"))]
mod clap {
use std::fmt::{self, Debug, Display};
pub struct Error(());
impl Display for Error {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unreachable!()
}
}
impl Debug for Error {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unreachable!()
}
}
impl std::error::Error for Error {}
}

View File

@@ -1,17 +1,6 @@
// `error_chain!` can recurse deeply
#![recursion_limit = "1024"]
extern crate ansi_term;
extern crate atty;
extern crate console;
extern crate content_inspector;
extern crate dirs as dirs_rs;
extern crate encoding;
extern crate git2;
extern crate shell_words;
extern crate syntect;
extern crate wild;
pub(crate) mod assets;
pub mod config;
pub(crate) mod controller;

View File

@@ -4,8 +4,6 @@ use std::io::{self, Write};
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use shell_words;
use crate::config::PagingMode;
use crate::errors::*;
use crate::less::retrieve_less_version;

View File

@@ -1,5 +1,3 @@
extern crate ansi_colours;
use ansi_term::Colour::{Fixed, RGB};
use ansi_term::{self, Style};