Skip to content

Commit

Permalink
Temporarily remove recursive (-r) flag (#266)
Browse files Browse the repository at this point in the history
* Remove recursive (`-r`) flag

* `cargo xtask gen`

* Remove unused `globwalk` and `ignore` deps
  • Loading branch information
CosmicHorrorDev authored Nov 2, 2023
1 parent e4e42a2 commit 79f5de0
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 138 deletions.
93 changes: 0 additions & 93 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ unescape = "0.1.0"
memmap2 = "0.9.0"
tempfile = "3.8.0"
thiserror = "1.0.50"
globwalk = "0.8.1"
ignore = "0.4.20"
ansi_term = "0.12.1"
is-terminal = "0.4.9"
clap.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions gen/completions/_sd
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ _sd() {
'-n+[Limit the number of replacements]:REPLACEMENTS: ' \
'-f+[Regex flags. May be combined (like \`-f mc\`).]:FLAGS: ' \
'--flags=[Regex flags. May be combined (like \`-f mc\`).]:FLAGS: ' \
'-p[Output result into stdout and do not modify files]' \
'--preview[Output result into stdout and do not modify files]' \
'-p[Display changes in a human reviewable format (the specifics of the format are likely to change in the future)]' \
'--preview[Display changes in a human reviewable format (the specifics of the format are likely to change in the future)]' \
'-F[Treat FIND and REPLACE_WITH args as literal strings]' \
'--fixed-strings[Treat FIND and REPLACE_WITH args as literal strings]' \
'-r[Recursively replace files]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
':find -- The regexp or string (if -s) to search for:' \
':find -- The regexp or string (if using `-F`) to search for:' \
':replace_with -- What to replace each match with. Unless in string mode, you may use captured values like $1, $2, etc:' \
'*::files -- The path to file(s). This is optional - sd can also read from STDIN:_files' \
&& ret=0
Expand Down
5 changes: 2 additions & 3 deletions gen/completions/_sd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ Register-ArgumentCompleter -Native -CommandName 'sd' -ScriptBlock {
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Limit the number of replacements')
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Regex flags. May be combined (like `-f mc`).')
[CompletionResult]::new('--flags', 'flags', [CompletionResultType]::ParameterName, 'Regex flags. May be combined (like `-f mc`).')
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output result into stdout and do not modify files')
[CompletionResult]::new('--preview', 'preview', [CompletionResultType]::ParameterName, 'Output result into stdout and do not modify files')
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Display changes in a human reviewable format (the specifics of the format are likely to change in the future)')
[CompletionResult]::new('--preview', 'preview', [CompletionResultType]::ParameterName, 'Display changes in a human reviewable format (the specifics of the format are likely to change in the future)')
[CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'Treat FIND and REPLACE_WITH args as literal strings')
[CompletionResult]::new('--fixed-strings', 'fixed-strings', [CompletionResultType]::ParameterName, 'Treat FIND and REPLACE_WITH args as literal strings')
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Recursively replace files')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
Expand Down
2 changes: 1 addition & 1 deletion gen/completions/sd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _sd() {

case "${cmd}" in
sd)
opts="-p -F -r -n -f -h -V --preview --fixed-strings --flags --help --version <FIND> <REPLACE_WITH> [FILES]..."
opts="-p -F -n -f -h -V --preview --fixed-strings --flags --help --version <FIND> <REPLACE_WITH> [FILES]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
5 changes: 2 additions & 3 deletions gen/completions/sd.elv
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ set edit:completion:arg-completer[sd] = {|@words|
cand -n 'Limit the number of replacements'
cand -f 'Regex flags. May be combined (like `-f mc`).'
cand --flags 'Regex flags. May be combined (like `-f mc`).'
cand -p 'Output result into stdout and do not modify files'
cand --preview 'Output result into stdout and do not modify files'
cand -p 'Display changes in a human reviewable format (the specifics of the format are likely to change in the future)'
cand --preview 'Display changes in a human reviewable format (the specifics of the format are likely to change in the future)'
cand -F 'Treat FIND and REPLACE_WITH args as literal strings'
cand --fixed-strings 'Treat FIND and REPLACE_WITH args as literal strings'
cand -r 'Recursively replace files'
cand -h 'Print help (see more with ''--help'')'
cand --help 'Print help (see more with ''--help'')'
cand -V 'Print version'
Expand Down
3 changes: 1 addition & 2 deletions gen/completions/sd.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
complete -c sd -s n -d 'Limit the number of replacements' -r
complete -c sd -s f -l flags -d 'Regex flags. May be combined (like `-f mc`).' -r
complete -c sd -s p -l preview -d 'Output result into stdout and do not modify files'
complete -c sd -s p -l preview -d 'Display changes in a human reviewable format (the specifics of the format are likely to change in the future)'
complete -c sd -s F -l fixed-strings -d 'Treat FIND and REPLACE_WITH args as literal strings'
complete -c sd -s r -d 'Recursively replace files'
complete -c sd -s h -l help -d 'Print help (see more with \'--help\')'
complete -c sd -s V -l version -d 'Print version'
9 changes: 3 additions & 6 deletions gen/sd.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sd
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.SH SYNOPSIS
\fBsd\fR [\fB\-p\fR|\fB\-\-preview\fR] [\fB\-F\fR|\fB\-\-fixed\-strings\fR] [\fB\-r \fR] [\fB\-n \fR] [\fB\-f\fR|\fB\-\-flags\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] <\fIFIND\fR> <\fIREPLACE_WITH\fR> [\fIFILES\fR]
\fBsd\fR [\fB\-p\fR|\fB\-\-preview\fR] [\fB\-F\fR|\fB\-\-fixed\-strings\fR] [\fB\-n \fR] [\fB\-f\fR|\fB\-\-flags\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] <\fIFIND\fR> <\fIREPLACE_WITH\fR> [\fIFILES\fR]
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.SH DESCRIPTION
Expand All @@ -17,14 +17,11 @@ sd
.SH OPTIONS
.TP
\fB\-p\fR, \fB\-\-preview\fR
Output result into stdout and do not modify files
Display changes in a human reviewable format (the specifics of the format are likely to change in the future)
.TP
\fB\-F\fR, \fB\-\-fixed\-strings\fR
Treat FIND and REPLACE_WITH args as literal strings
.TP
\fB\-r\fR
Recursively replace files
.TP
\fB\-n\fR=\fIREPLACEMENTS\fR
Limit the number of replacements
.TP
Expand All @@ -50,7 +47,7 @@ Print help (see a summary with \*(Aq\-h\*(Aq)
Print version
.TP
<\fIFIND\fR>
The regexp or string (if \-s) to search for
The regexp or string (if using `\-F`) to search for
.TP
<\fIREPLACE_WITH\fR>
What to replace each match with. Unless in string mode, you may use captured values like $1, $2, etc
Expand Down
4 changes: 0 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub struct Options {
/// Treat FIND and REPLACE_WITH args as literal strings
pub literal_mode: bool,

#[arg(short)]
/// Recursively replace files
pub recursive: bool,

#[arg(short = 'n')]
/// Limit the number of replacements
pub replacements: Option<usize>,
Expand Down
17 changes: 0 additions & 17 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ pub(crate) enum Source {
Files(Vec<PathBuf>),
}

impl Source {
pub(crate) fn recursive() -> Result<Self> {
Ok(Self::Files(
ignore::WalkBuilder::new(".")
.hidden(false)
.filter_entry(|e| e.file_name() != ".git")
.build()
.filter_map(|d| d.ok())
.filter_map(|d| match d.file_type() {
Some(t) if t.is_file() => Some(d.into_path()),
_ => None,
})
.collect(),
))
}
}

pub(crate) struct App {
replacer: Replacer,
source: Source,
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ fn main() {
fn try_main() -> Result<()> {
let options = cli::Options::parse();

let source = if options.recursive {
Source::recursive()?
} else if !options.files.is_empty() {
let source = if !options.files.is_empty() {
Source::Files(options.files)
} else {
Source::Stdin
Expand Down

0 comments on commit 79f5de0

Please sign in to comment.