From cdcc53dd62e91e6ae93f6d28e5b2befd0f62e6ad Mon Sep 17 00:00:00 2001 From: Nev Delap Date: Sat, 2 Feb 2019 22:42:53 +1000 Subject: [PATCH] Issue 66: ned man page. --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 140 ++++++++++++++++---------------- man/compare | 8 ++ man/install | 3 + man/ned.1 | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++ man/ned.1.gz | Bin 0 -> 2214 bytes man/watch | 5 ++ src/opts.rs | 113 +++++++++++++------------- 9 files changed, 369 insertions(+), 125 deletions(-) create mode 100755 man/compare create mode 100755 man/install create mode 100644 man/ned.1 create mode 100644 man/ned.1.gz create mode 100755 man/watch diff --git a/Cargo.lock b/Cargo.lock index 19010bf..85e413b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "ned" -version = "1.2.7" +version = "1.2.8" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 2ab069a..105b773 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ [package] name = "ned" -version = "1.2.7" +version = "1.2.8" authors = ["Nev Delap "] [dependencies] diff --git a/README.md b/README.md index 25597cb..00702d1 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,13 @@ quick and easy example usages. ```text -Usage: ned [OPTION]... [-p] [FILE]... +> ned --help + +Usage: ned [OPTION...] [-p] PATTERN [FILE...] + ned [OPTION...] [FILE...] -p PATTERN For regular expression power users, ned is like grep, but with -powerful replace capabilities, and more powerful than sed, as it +powerful replace capabilities, and unlike sed, as it isn't restricted to line oriented editing. FILEs are ASCII or UTF-8 text files. For regex syntax see: @@ -21,75 +24,78 @@ FILEs are ASCII or UTF-8 text files. For regex syntax see: Options: -p, --pattern PATTERN - specify pattern. if the option isn't used the pattern - must precede the files. the option allows the pattern - to be put after the files for more convenient editing + Specify a pattern. If the option isn't used the + pattern must precede the files. The option allows the + pattern to be put after the files for more convenient + editing. -r, --replace REPLACEMENT - replace matches, may include named groups. replaces - always operate on whole files - -w, --whole-files operate on whole files. otherwise matches are line - oriented - -n, --number N match/replace N occurrences - -k, --skip N skip N occurrences before matching/replacing - -b, --backwards -n --number and -k --skip options count backwards - -i, --ignore-case ignore case - -s, --single . matches newlines, ^ and $ match beginning and end of - each file. use with --whole-files - -m, --multiline multiline, ^ and $ match beginning and end of each - line. use with --whole-files - -x, --extended ignore whitespace and # comments + Replace matches. Replacements may include numbered and + named groups. Replaces always operate on whole files. + -w, --whole-files Operate on whole files. Otherwise matches are line + oriented. + -n, --number N Match/replace N occurrences. + -k, --skip N Skip N occurrences before matching/replacing. + -b, --backwards Make -n/--number and -k/--skip options count + backwards. + -i, --ignore-case Ignore case. + -s, --single '.' matches newlines, ^ and $ match the beginning and + end of each file. Use with --whole-files. + -m, --multiline Multiline, ^ and $ match the beginning and end of each + line. Use with --whole-files. + -x, --extended Ignore whitespace and # comments. --case-replacements - enable \U - uppercase, \L - lowercase, \I - initial + Enable \U - uppercase, \L - lowercase, \I - initial uppercase (title case), \F - first uppercase (sentence case) replacements. \E marks the end of a case - replacement - -o, --matches-only show only matches - -g, --group GROUP show the match group, specified by number or name - -v, --no-match show only non-matching + replacement. + -o, --matches-only Show only matches. + -g, --group GROUP Show the match group, specified by number or name. + -v, --no-match Show only non-matching. -f, --filenames-only - show only filenames containing matches. use with -v - --no-match to show filenames without matches - -F, --no-filenames don't show filesnames + Show only filenames containing matches. Use with + -v/--no-match to show filenames without matches. + -F, --no-filenames Don't show filenames. -l, --line-numbers-only - show only line numbers containing matches. use with -v - --no-match to show line numbers without matches. use - without -w --whole-files + Show only line numbers containing matches. Use with + -v/--no-match to show line numbers without matches. + Use without -w/--whole-files. -L, --no-line-numbers - don't show line numbers, use without -w --whole-files - -C, --context LINES show LINES lines around each matching line. is the - same as specifying both -B --before and -A --after - with the same LINES. use without -w --whole-files - -B, --before LINES show LINES lines before each matching line. use - without -w --whole-files - -A, --after LINES show LINES lines after each matching line. use without - -w --whole-files - -R, --recursive recurse - -l, --follow follow symlinks (Ignored on Windows.) - --include GLOB match only files that match GLOB - --exclude GLOB skip files matching GLOB + Don't show line numbers. Use without -w/--whole-files. + -C, --context LINES Show LINES lines around each matching line. Is the + same as specifying both -B/--before and -A/--after + with the same LINES. Use without -w/--whole-files. + -B, --before LINES Show LINES lines before each matching line. Use + without -w/--whole-files. + -A, --after LINES Show LINES lines after each matching line. Use without + -w/--whole-files. + -R, --recursive Recurse. + -l, --follow Follow symlinks. (Ignored on Windows.) + --include GLOB Match only files that match GLOB. + --exclude GLOB Skip files matching GLOB. --exclude-dir GLOB - skip directories matching GLOB + Skip directories matching GLOB. -u, --ignore-non-utf8 - quietly ignore files that cannot be parsed as UTF-8 - (or ASCII). because this requires reading the file the - --exclude option should be preferred - -a, --all do not ignore entries starting with . - -c show filenames, line numbers, and matches in color. is - the same as --colors=always + Quietly ignore files that cannot be parsed as UTF-8 + (or ASCII). Because this requires reading the file, + the --exclude option should be preferred. + -a, --all Do not ignore files and directories starting with '.'. + -c Show filenames, line numbers, and matches in color. Is + the same as --colors=always. --colors [WHEN] 'auto' shows filenames, line numbers, and matches in color when stdout is a terminal, not when it is a pipe, 'always' shows color even when stdout is a pipe, - and 'never' never shows colors - --stdout output to stdout - -q, --quiet suppress all normal output - -V, --version output version information and exit - -h, --help print this help and exit + and 'never' never shows colors. + --stdout Output to stdout. + -q, --quiet Suppress all normal output. When matching terminate as + soon as a match is found. + -V, --version Output version information and exit. + -h, --help Print this help and exit. Environment: - NED_DEFAULTS ned options added to the program's arguments. is + NED_DEFAULTS ned options added to the program's arguments. Is a space delimited list of options and is not first - interpreted by a shell, so quotes are not required. - for example... + interpreted by a shell, so quotes are not required + around arguments. For example: NED_DEFAULTS="-u -R --exclude *.bk --exclude-dir .git" Exit codes: @@ -97,12 +103,12 @@ Exit codes: 1 no matches Quiet: - When -q (--quiet) is specified, ned tests for matches and returns an exit + When -q/--quiet is specified, ned tests for matches and returns an exit code of 0 if a match is found in ANY file. Quiet matches will only read as many files as needed to find a match. Even without this shortcutting behaviour, quiet matches are more performant than non-quiet matches. -ned 1.2.7 Copyright (C) 2016-2019 Nev Delap - https://github.com/nevdelap/ned +ned 1.2.8 Copyright (C) 2016-2019 Nev Delap - https://github.com/nevdelap/ned License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. @@ -110,7 +116,7 @@ There is NO WARRANTY, to the extent permitted by law. ``` -## I.A.Q. (Infrequently Asked Questions) +# I.A.Q. (Infrequently Asked Questions) ***Why isn't \U working? (or \L, \I, \F)*** @@ -142,13 +148,13 @@ ignore non-ASCII, non-UTF-8 files you can put this in NED_DEFAULTS. See the help Git Bash does not support colored output using ansi_term. Run the tests in cmd.exe. -## Machine Setup To Build `ned` +# Building `ned` + +### Machine Setup To Build `ned` * Install rust as per: https://www.rust-lang.org/en-US/install.html * (Windows) Install Visual Studio Build Tools 2017 as per: https://www.visualstudio.com/downloads/ -# Building `ned` - ### To build for the current platform. Last tested on Manjaro 18.0.2 up-to-date, on Windows 10.0.17134.523, and on OS X High Sierra 13.1.6, with Rust 1.32.0. @@ -158,12 +164,10 @@ cd ned cargo build --release cargo test ... -test result: ok. 136 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out +test result: ok. 137 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` -# Installing `ned` - ### To build for 64bit musl. Last tested on Manjaro 18.0.2 up-to-date, with Rust 1.32.0. @@ -174,10 +178,12 @@ rustup target add x86_64-unknown-linux-musl cargo build --release --target x86_64-unknown-linux-musl cargo test --target x86_64-unknown-linux-musl ... -test result: ok. 136 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out +test result: ok. 137 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` +# Installing `ned` + ### To Install in Arch and Manjaro and other Arch based distros. ``` yum -S ned @@ -185,7 +191,7 @@ yum -S ned ### To Install in Debian, Ubuntu and other Debian based distros. -Download the 64-bit or 32-bit deb file from the latest release: https://github.com/nevdelap/ned/releases. They package a single musl binary of `ned` with no dependencies. +Download the 64-bit or 32-bit deb file from the latest release: https://github.com/nevdelap/ned/releases. They package a single musl binary of `ned` and its man page with no dependencies. # TL;DR diff --git a/man/compare b/man/compare new file mode 100755 index 0000000..edbac9f --- /dev/null +++ b/man/compare @@ -0,0 +1,8 @@ +#!/bin/sh +# Compare the help and man texts. Most of the middle +# should be identical because it is in the same order. +clear +cargo run -- --help > /tmp/help.txt +man ./ned.1 > /tmp/man.txt +ned '\s' -r '' /tmp/help.txt /tmp/man.txt +git diff --color-words=. -w /tmp/help.txt /tmp/man.txt diff --git a/man/install b/man/install new file mode 100755 index 0000000..148ef15 --- /dev/null +++ b/man/install @@ -0,0 +1,3 @@ +#!/bin/sh +gzip --stdout ned.1 > ned.1.gz +sudo install -g 0 -o 0 -m 0644 ned.1.gz /usr/share/man/man1/ diff --git a/man/ned.1 b/man/ned.1 new file mode 100644 index 0000000..6e95403 --- /dev/null +++ b/man/ned.1 @@ -0,0 +1,221 @@ +.\" Manpage for ned. +.\" Contact nevdelap@gmail.com to correct errors or typos. +.TH ned 1 "2019-02-03" "ned 1.2.8" +.SH NAME +.B ned +- Powerful regex replace for bulk editing. +.SH SYNOPSIS +.B ned +.RI [ OPTION ...] \& +.RB [ -p ] +.I PATTERN +.RI [ FILE ...] +.br +.B ned +.RI [ OPTION "...] [" FILE ...] \& +.BI -p " PATTERN" +.SH DESCRIPTION +.RB "For regular expression power users, " ned " is like " grep ", but with powerful replace capabilities, and unlike " sed ", as it isn't restricted to line oriented editing." + +FILEs are ASCII or UTF-8 text files. For regex syntax see: https://docs.rs/regex/1.1.0/regex/#syntax +.SH OPTIONS +.BR -p ", " --pattern " PATTERN" +.RS +Specify a pattern. If the option isn't used the pattern must precede the files. The option allows the pattern to be put after the files for more convenient editing. + +.RE +.BR -r ", " --replace " REPLACEMENT" +.RS +Replace matches. Replacements may include numbered and named groups. Replaces always operate on whole files. + +.RE +.BR -w ", " --whole-files +.RS +Operate on whole files. Otherwise matches are line oriented. + +.RE +.BR -n ", " --number " N" +.RS +Match/replace N occurrences. + +.RE +.BR -k ", " --skip " N" +.RS +Skip N occurrences before matching/replacing. + +.RE +.BR -b ", " --backwards +.RS +.RB "Make " -n/--number " and " -k/--skip " options count backwards." + +.RE +.BR -i ", " --ignore-case +.RS +Ignore case. + +.RE +.BR -s ", " --single +.RS +.RB "'.' matches newlines, ^ and $ match the beginning and end of each file. Use with " --whole-files "." + +.RE +.BR -m ", " --multiline +.RS +.RB "Multiline, ^ and $ match the beginning and end of each line. Use with " --whole-files "." + +.RE +.BR -x ", " --extended +.RS +Ignore whitespace and # comments. + +.RE +.BR --case-replacements +.RS +Enable \\U - uppercase, \\L - lowercase, \\I - initial uppercase (title case), \\F - first uppercase (sentence case) replacements. \\E marks the end of a case replacement. + +.RE +.BR -o ", " --matches-only +.RS +Show only matches. + +.RE +.BR -g ", " --group " GROUP" +.RS +Show the match group, specified by number or name. + +.RE +.BR -v ", " --no-match +.RS +Show only non-matching. + +.RE +.BR -f ", " --filenames-only +.RS +.RB "Show only filenames containing matches. Use with " -v/--no-match " to show filenames without matches." + +.RE +.BR -F ", " --no-filenames +.RS +Don't show filenames. + +.RE +.BR -l ", " --line-numbers-only +.RS +.RB "Show only line numbers containing matches. Use with " -v/--no-match " to show line numbers without matches. Use without " -w/--whole-files "." + +.RE +.BR -L ", " --no-line-numbers +.RS +.RB "Don't show line numbers. Use without " -w/--whole-files "." + +.RE +.BR -C ", " --context " LINES" +.RS +.RB "Show LINES lines around each matching line. Is the same as specifying both " -B/--before " and " -A/--after " with the same LINES. Use without " -w/--whole-files "." + +.RE +.BR -B ", " --before " LINES" +.RS +.RB "Show LINES lines before each matching line. Use without " -w/--whole-files "." + +.RE +.BR -A ", " --after " LINES" +.RS +.RB "Show LINES lines after each matching line. Use without " -w/--whole-files "." + +.RE +.BR -R ", " --recursive +.RS +Recurse. + +.RE +.BR -l ", " --follow +.RS +Follow symlinks. (Ignored on Windows.) + +.RE +.BR --include " GLOB" +.RS +Match only files that match GLOB. + +.RE +.BR --exclude " GLOB" +.RS +Skip files matching GLOB. + +.RE +.BR --exclude-dir " GLOB" +.RS +Skip directories matching GLOB. + +.RE +.BR -u ", " --ignore-non-utf8 +.RS +.RB "Quietly ignore files that cannot be parsed as UTF-8 (or ASCII). Because this requires reading the file, the " --exclude " option should be preferred." + +.RE +.BR -a ", " --all +.RS +Do not ignore files and directories starting with '.'. + +.RE +.B -c +.RS +.RB "Show filenames, line numbers, and matches in color. Is the same as " --colors=always "." + +.RE +.BR --colors +.RI [ WHEN ] +.RS +\'auto' shows filenames, line numbers, and matches in color when stdout is a terminal, not when it is a pipe, 'always' shows color even when stdout is a pipe, and 'never' never shows colors. + +.RE +.BR --stdout +.RS +Output to stdout. + +.RE +.BR -q ", " --quiet +.RS +Suppress all normal output. When matching terminate as soon as a match is found. + +.RE +.BR -V ", " --version +.RS +Output version information and exit. + +.RE +.BR -h ", " --help +.RS +Print this help and exit. + +.RE + +Quiet +.RS +.RB "When " -q/--quiet " is specified, " ned " tests for matches and returns an exit code of 0 if a match is found in ANY file. Quiet matches will only read as many files as needed to find a match. Even without this shortcutting behaviour, quiet matches are more performant than non-quiet matches." + +.RE +.SH EXIT STATUS +An exit status of 0 means matches were found/replaced. An exit status of 1 means no matches were found. +.SH ENVIRONMENT +.B NED_DEFAULTS +.RS +.RB "Specifies " ned " options added to the program's arguments. Is a space delimited list of options and is not first interpreted by a shell, so quotes are not required around arguments. For example:" +.PP +NED_DEFAULTS="-u -R --exclude *.bk --exclude-dir .git" +.RE +.SH EXAMPLES +.RB "The TL;DR section of the " ned " README.md gives example usages." + +https://github.com/nevdelap/ned#tldr +.SH SEE ALSO +https://github.com/nevdelap/ned/wiki +.SH AUTHOR +Nev Delap (nevdelap@gmail.com) +.SH COPYRIGHT +.BR ned " 1.2.8 Copyright (C) 2016-2019 Nev Delap" +.SH LICENSE +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. diff --git a/man/ned.1.gz b/man/ned.1.gz new file mode 100644 index 0000000000000000000000000000000000000000..26ecb9bde8d7145a077778058b29ae908128932a GIT binary patch literal 2214 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 oGDc(ewLhKqNAqu|Azf*vwOFQ*ls?gNzKuJ-0! Options { opts.optopt( "p", "pattern", - "specify pattern. if the option isn't used the pattern must precede the files. \ - the option allows the pattern to be put after the files for more convenient \ - editing", + "Specify a pattern. If the option isn't used the pattern must precede the files. \ + The option allows the pattern to be put after the files for more convenient \ + editing.", "PATTERN", ); opts.optopt( "r", "replace", - "replace matches, may include named groups. replaces always operate on whole \ - files", + "Replace matches. Replacements may include numbered and named groups. Replaces always operate on whole \ + files.", "REPLACEMENT", ); opts.optflag( "w", "whole-files", - "operate on whole files. otherwise matches are line oriented", + "Operate on whole files. Otherwise matches are line oriented.", ); - opts.optopt("n", "number", "match/replace N occurrences", "N"); + opts.optopt("n", "number", "Match/replace N occurrences.", "N"); opts.optopt( "k", "skip", - "skip N occurrences before matching/replacing", + "Skip N occurrences before matching/replacing.", "N", ); opts.optflag( "b", "backwards", - "-n --number and -k --skip options count backwards", + "Make -n/--number and -k/--skip options count backwards.", ); - opts.optflag("i", "ignore-case", "ignore case"); + opts.optflag("i", "ignore-case", "Ignore case."); opts.optflag( "s", "single", - ". matches newlines, ^ and $ match beginning and end of each file. use \ - with --whole-files", + "'.' matches newlines, ^ and $ match the beginning and end of each file. Use \ + with --whole-files.", ); opts.optflag( "m", "multiline", - "multiline, ^ and $ match beginning and end of each line. use with \ - --whole-files", + "Multiline, ^ and $ match the beginning and end of each line. Use with \ + --whole-files.", ); - opts.optflag("x", "extended", "ignore whitespace and # comments"); + opts.optflag("x", "extended", "Ignore whitespace and # comments."); opts.optflag( "", "case-replacements", - "enable \\U - uppercase, \\L - \ + "Enable \\U - uppercase, \\L - \ lowercase, \\I - initial uppercase (title case), \\F - first uppercase \ - (sentence case) replacements. \\E marks the end of a case replacement", + (sentence case) replacements. \\E marks the end of a case replacement.", ); - opts.optflag("o", "matches-only", "show only matches"); + opts.optflag("o", "matches-only", "Show only matches."); opts.optopt( "g", "group", - "show the match group, specified by number or name", + "Show the match group, specified by number or name.", "GROUP", ); - opts.optflag("v", "no-match", "show only non-matching"); + opts.optflag("v", "no-match", "Show only non-matching."); opts.optflag( "f", "filenames-only", - "show only filenames containing matches. use with -v \ - --no-match to show filenames without matches", + "Show only filenames containing matches. Use with -v/\ + --no-match to show filenames without matches.", ); - opts.optflag("F", "no-filenames", "don't show filesnames"); + opts.optflag("F", "no-filenames", "Don't show filenames."); opts.optflag( "l", "line-numbers-only", - "show only line numbers containing matches. use with -v \ - --no-match to show line numbers without matches. use without -w \ - --whole-files", + "Show only line numbers containing matches. Use with -v/\ + --no-match to show line numbers without matches. Use without -w/\ + --whole-files.", ); opts.optflag( "L", "no-line-numbers", - "don't show line numbers, use without -w --whole-files", + "Don't show line numbers. Use without -w/--whole-files.", ); opts.optopt( "C", "context", - "show LINES lines around each matching line. is the same as \ - specifying both -B --before and -A --after with the same LINES. use without -w \ - --whole-files", + "Show LINES lines around each matching line. Is the same as \ + specifying both -B/--before and -A/--after with the same LINES. Use without -w/\ + --whole-files.", "LINES", ); opts.optopt( "B", "before", - "show LINES lines before each matching line. use without -w \ - --whole-files", + "Show LINES lines before each matching line. Use without -w/\ + --whole-files.", "LINES", ); opts.optopt( "A", "after", - "show LINES lines after each matching line. use without -w \ - --whole-files", + "Show LINES lines after each matching line. Use without -w/\ + --whole-files.", "LINES", ); - opts.optflag("R", "recursive", "recurse"); - opts.optflag("l", "follow", "follow symlinks (Ignored on Windows.)"); - opts.optmulti("", "include", "match only files that match GLOB", "GLOB"); - opts.optmulti("", "exclude", "skip files matching GLOB", "GLOB"); - opts.optmulti("", "exclude-dir", "skip directories matching GLOB", "GLOB"); + opts.optflag("R", "recursive", "Recurse."); + opts.optflag("l", "follow", "Follow symlinks. (Ignored on Windows.)"); + opts.optmulti("", "include", "Match only files that match GLOB.", "GLOB"); + opts.optmulti("", "exclude", "Skip files matching GLOB.", "GLOB"); + opts.optmulti("", "exclude-dir", "Skip directories matching GLOB.", "GLOB"); opts.optflag( "u", "ignore-non-utf8", - "quietly ignore files that cannot be parsed as UTF-8 (or ASCII). because \ - this requires reading the file the --exclude option should be preferred", + "Quietly ignore files that cannot be parsed as UTF-8 (or ASCII). Because \ + this requires reading the file, the --exclude option should be preferred.", ); - opts.optflag("a", "all", "do not ignore entries starting with ."); - opts.optflag("c", "", "show filenames, line numbers, and matches in color. is the same as --colors=always"); + opts.optflag("a", "all", "Do not ignore files and directories starting with '.'."); + opts.optflag("c", "", "Show filenames, line numbers, and matches in color. Is the same as --colors=always."); opts.optflagopt( "", "colors", - "'auto' shows filenames, line numbers, and matches in color when stdout is a terminal, not when it is a pipe, 'always' shows color even when stdout is a pipe, and 'never' never shows colors", + "'auto' shows filenames, line numbers, and matches in color when stdout is a terminal, not when it is a pipe, 'always' shows color even when stdout is a pipe, and 'never' never shows colors.", "WHEN", ); - opts.optflag("", "stdout", "output to stdout"); - opts.optflag("q", "quiet", "suppress all normal output"); - opts.optflag("V", "version", "output version information and exit"); - opts.optflag("h", "help", "print this help and exit"); + opts.optflag("", "stdout", "Output to stdout."); + opts.optflag("q", "quiet", "Suppress all normal output. When matching terminate as soon as a match is found."); + opts.optflag("V", "version", "Output version information and exit."); + opts.optflag("h", "help", "Print this help and exit."); opts } @@ -203,8 +204,8 @@ pub fn usage_version() -> String { pub fn usage_brief() -> String { format!( - "Usage: {} {}\n\n{}", - PROGRAM, &OPTS_AND_ARGS, &PRE_DESCRIPTION + "{}\n\n{}", + &USAGE, &PRE_DESCRIPTION ) }