Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Nov 13, 2023
1 parent 22d6b52 commit 117a9c4
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 157 deletions.
44 changes: 1 addition & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ members = [
"crates/ignore",
]

[patch.crates-io]
termcolor = { path = "/home/andrew/rust/termcolor" }

[dependencies]
aho-corasick = "1.1.2"
anyhow = "1.0.75"
Expand All @@ -60,18 +63,18 @@ serde_json = "1.0.23"
termcolor = "1.1.0"
textwrap = { version = "0.16.0", default-features = false }

[dependencies.clap]
version = "2.33.0"
default-features = false
features = ["suggestions"]
# [dependencies.clap]
# version = "2.33.0"
# default-features = false
# features = ["suggestions"]

[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
version = "0.5.0"

[build-dependencies.clap]
version = "2.33.0"
default-features = false
features = ["suggestions"]
# [build-dependencies.clap]
# version = "2.33.0"
# default-features = false
# features = ["suggestions"]

[dev-dependencies]
serde = "1.0.77"
Expand Down
67 changes: 31 additions & 36 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
use std::{
env,
fs::{self, File},
io::{self, Read, Write},
path::Path,
process,
};
use std::{env, process};

use clap::Shell;
// use clap::Shell;

use crate::app::{RGArg, RGArgKind};
// use crate::app::{RGArg, RGArgKind};

#[allow(dead_code)]
#[path = "crates/core/app.rs"]
mod app;
// #[allow(dead_code)]
// #[path = "crates/core/app.rs"]
// mod app;

fn main() {
// OUT_DIR is set by Cargo and it's where any additional build artifacts
// are written.
let Some(outdir) = env::var_os("OUT_DIR") else {
eprintln!(
"OUT_DIR environment variable not defined. \
Please file a bug: \
https://github.com/BurntSushi/ripgrep/issues/new"
);
process::exit(1);
};
fs::create_dir_all(&outdir).unwrap();

let stamp_path = Path::new(&outdir).join("ripgrep-stamp");
if let Err(err) = File::create(&stamp_path) {
panic!("failed to write {}: {}", stamp_path.display(), err);
}
if let Err(err) = generate_man_page(&outdir) {
eprintln!("failed to generate man page: {}", err);
}
// // OUT_DIR is set by Cargo and it's where any additional build artifacts
// // are written.
// let Some(outdir) = env::var_os("OUT_DIR") else {
// eprintln!(
// "OUT_DIR environment variable not defined. \
// Please file a bug: \
// https://github.com/BurntSushi/ripgrep/issues/new"
// );
// process::exit(1);
// };
// fs::create_dir_all(&outdir).unwrap();
//
// let stamp_path = Path::new(&outdir).join("ripgrep-stamp");
// if let Err(err) = File::create(&stamp_path) {
// panic!("failed to write {}: {}", stamp_path.display(), err);
// }
// if let Err(err) = generate_man_page(&outdir) {
// eprintln!("failed to generate man page: {}", err);
// }

// Use clap to build completion files.
let mut app = app::app();
app.gen_completions("rg", Shell::Bash, &outdir);
app.gen_completions("rg", Shell::Fish, &outdir);
app.gen_completions("rg", Shell::PowerShell, &outdir);
// let mut app = app::app();
// app.gen_completions("rg", Shell::Bash, &outdir);
// app.gen_completions("rg", Shell::Fish, &outdir);
// app.gen_completions("rg", Shell::PowerShell, &outdir);
// Note that we do not use clap's support for zsh. Instead, zsh completions
// are manually maintained in `complete/_rg`.

Expand Down Expand Up @@ -90,6 +84,7 @@ fn git_revision_hash() -> Option<String> {
}
}

/*
fn generate_man_page<P: AsRef<Path>>(outdir: P) -> io::Result<()> {
// If asciidoctor isn't installed, fallback to asciidoc.
if let Err(err) = process::Command::new("asciidoctor").output() {
Expand Down Expand Up @@ -246,7 +241,6 @@ fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
// Hack to render ** literally in man page correctly. We can't put
// these crazy +++ in the help text directly, since that shows
// literally in --help output.
.replace("*-g 'foo/**'*", "*-g +++'foo/**'+++*")
.split("\n\n")
.map(|s| s.to_string())
.collect();
Expand All @@ -263,3 +257,4 @@ fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
fn ioerr(msg: String) -> io::Error {
io::Error::new(io::ErrorKind::Other, msg)
}
*/
8 changes: 4 additions & 4 deletions crates/core/flags/lowargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(crate) struct LowArgs {
/// fail too, but usually not in a way that can't be worked around by removing
/// the corresponding arguments from the CLI command.) This is overall a hedge
/// to ensure that version and help information are basically always available.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum SpecialMode {
/// Show a condensed version of "help" output. Generally speaking, this
/// shows each flag and an extremely terse description of that flag on
Expand All @@ -128,7 +128,7 @@ pub(crate) enum SpecialMode {
/// Note that -h/--help is not included in this because -h/--help always
/// overrides everything else, regardless of where it appears in the command
/// line.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum Mode {
/// ripgrep will execute a search of some kind.
Search(SearchMode),
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Mode {
}

/// The kind of search that ripgrep is going to perform.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum SearchMode {
/// The default standard mode of operation. ripgrep looks for matches and
/// prints them when found.
Expand All @@ -193,7 +193,7 @@ pub(crate) enum SearchMode {
}

/// The thing to generate via the --generate flag.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum GenerateMode {
/// Generate the raw roff used for the man page.
Man,
Expand Down
18 changes: 9 additions & 9 deletions crates/core/flags/midargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl MidArgs {
///
/// If there was a problem building the matcher (e.g., a syntax error),
/// then this returns an error.
fn matcher(&self) -> anyhow::Result<PatternMatcher> {
pub(crate) fn matcher(&self) -> anyhow::Result<PatternMatcher> {
match self.engine {
EngineChoice::Default => match self.matcher_rust() {
Ok(m) => Ok(m),
Expand Down Expand Up @@ -524,29 +524,29 @@ impl MidArgs {
Ok(builder.build()?)
}

/// Returns a printer only when the current mode is `Mode::Search`.
/// Returns a printer for the given search mode.
pub(crate) fn printer<W: termcolor::WriteColor>(
&self,
search_mode: SearchMode,
wtr: W,
) -> Option<Printer<W>> {
let Mode::Search(ref search_mode) = self.mode else { return None };
) -> Printer<W> {
let summary_kind = if self.quiet {
SummaryKind::Quiet
} else {
match *search_mode {
match search_mode {
SearchMode::FilesWithMatches => SummaryKind::PathWithMatch,
SearchMode::FilesWithoutMatch => SummaryKind::PathWithoutMatch,
SearchMode::Count => SummaryKind::Count,
SearchMode::CountMatches => SummaryKind::CountMatches,
SearchMode::JSON => {
return Some(Printer::JSON(self.printer_json(wtr)))
return Printer::JSON(self.printer_json(wtr))
}
SearchMode::Standard => {
return Some(Printer::Standard(self.printer_standard(wtr)))
return Printer::Standard(self.printer_standard(wtr))
}
}
};
Some(Printer::Summary(self.printer_summary(wtr, summary_kind)))
Printer::Summary(self.printer_summary(wtr, summary_kind))
}

fn printer_json<W: std::io::Write>(
Expand Down Expand Up @@ -781,7 +781,7 @@ impl MidArgs {

pub(crate) fn walk_builder(&self) -> anyhow::Result<ignore::WalkBuilder> {
let mut builder = ignore::WalkBuilder::new(&self.paths.paths[0]);
for path in self.paths.paths.iter() {
for path in self.paths.paths.iter().skip(1) {
builder.add(path);
}
if !self.no_ignore_files {
Expand Down
3 changes: 2 additions & 1 deletion crates/core/flags/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub(crate) use crate::flags::{
},
man::generate as generate_man_page,
},
lowargs::{GenerateMode, Mode, SearchMode, SpecialMode},
midargs::MidArgs,
parse::parse,
parse::{parse, ParseResult},
};

mod complete;
Expand Down
Loading

0 comments on commit 117a9c4

Please sign in to comment.