From 323dcc026144f505ca8937ffd0e2ddd2352eea6b Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Tue, 19 Jul 2022 12:04:05 +0200 Subject: [PATCH] 0.0.15 --- Changes | 5 ++++ META6.json | 2 +- README.md | 62 +++++++++++++++++++++++++++++-------------- lib/App/Rak.rakumod | 64 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 99 insertions(+), 34 deletions(-) diff --git a/Changes b/Changes index 226cc7e..5196257 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,11 @@ Revision history for App-Rak {{$NEXT}} +0.0.15 2022-07-19T12:03:57+02:00 + - Add support for -I functionality + - Add support for -M functionality + - Worked a bit on the pod + 0.0.14 2022-07-18T20:47:50+02:00 - Add dependency on META::constants - Add dependency on CLI::Help to get --help support diff --git a/META6.json b/META6.json index f725e8d..b46939e 100644 --- a/META6.json +++ b/META6.json @@ -35,5 +35,5 @@ ], "test-depends": [ ], - "version": "0.0.14" + "version": "0.0.15" } diff --git a/README.md b/README.md index 09b411f..7af2330 100644 --- a/README.md +++ b/README.md @@ -51,18 +51,18 @@ SUPPORTED OPTIONS All options are optional. Any unexpected options, will cause an exception to be thrown with the unexpected options listed. ---after-context ---------------- +--after-context=N +----------------- Indicate the number of lines that should be shown **after** any line that matches. Defaults to **0**. Will be overridden by a `--context` argument. ---before-context ----------------- +--before-context=N +------------------ Indicate the number of lines that should be shown **before** any line that matches. Defaults to **0**. Will be overridden by a `--context` argument. ---context ---------- +--context=N +----------- Indicate the number of lines that should be shown **around** any line that matches. Defaults to **0**. Overrides any a `--after-context` or `--before-context` arguments. @@ -71,11 +71,26 @@ Indicate the number of lines that should be shown **around** any line that match Indicate whether just the number of lines with matches should be calculated. When specified with a `True` value, will show a "N matches in M files" by default, and if the `:files-with-matches` option is also specified with a `True` value, will also list the file names with their respective counts. ---edit ------- +--edit[=editor] +--------------- Indicate whether the patterns found should be fed into an editor for inspection and/or changes. Defaults to `False`. Optionally takes the name of the editor to be used. +-I=dir +------ + +Indicate the directory that should be searched for Raku module loading. Only makes sense if the pattern is executable code. + +Please note that contrary to normal use in Raku, the `=` **must** be specified. Also note that you can create a shortcut for most often used arguments of the `-I` option: + +```bash +$ rak --I=. --save=I. +Saved option '--I.' as: --I='.' + +$ rak --I=lib --save=Ilib +Saved option '--Ilib' as: --I=lib +``` + --no-filename ------------- @@ -86,13 +101,13 @@ Indicate whether filenames should **not** be shown. Defaults to `False` if `--hu Indicate whether the pattern should be highlighted in the line in which it was found. Defaults to `True` if `--human` is (implicitly) set to `True`, else defaults to `False`. ---highlight--after ------------------- +--highlight--after[=string] +--------------------------- Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitly) set to `True`. Defaults to the empty string if `--only-matching` is specified with a `True` value, or to the terminal code to end **bold** otherwise. ---highlight--before -------------------- +--highlight--before[=string] +---------------------------- Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitly) set to `True`. Defaults to a space if `--only-matching` is specified with a `True` value, or to the terminal code to start **bold** otherwise. @@ -122,18 +137,25 @@ If specified with a true value and as the only option, will list all additional Indicate whether line numbers should be shown. Defaults to `True` if `--human` is (implicitly) set to `True` and <-h> is **not** set to `True`, else defaults to `False`. +-M=module +--------- + +Indicate the Raku module that should be loaded. Only makes sense if the pattern is executable code. + +Please note that contrary to normal use in Raku, the `=` **must** be specified. + --only-matching --------------- Indicate whether only the matched pattern should be produced, rather than the line in which the pattern was found. Defaults to `False`. ---output-file -------------- +--output-file=filename +---------------------- Indicate the path of the file in which the result of the search should be placed. Defaults to `STDOUT`. ---pattern ---------- +--pattern=foo +------------- Alternative way to specify the pattern to search for. If (implicitly) specified, will assume the first positional parameter specified is actually a path specification, rather than a pattern. This allows the pattern to be searched for to be saved with `--save`. @@ -142,8 +164,8 @@ Alternative way to specify the pattern to search for. If (implicitly) specified, Only makes sense if the specified pattern is a `Callable`. Indicates whether the output of the pattern should be applied to the file in which it was found. Defaults to `False`. ---save ------- +--save=name +----------- Save all named arguments with the given name in the configuration file (`~/.rak-config.json`), and exit with a message that these options have been saved with the given name. @@ -167,8 +189,8 @@ Any saved named arguments can be accessed as if it is a standard named boolean a To remove a saved set of named arguments, use `--save` as the only named argument. ---summary-if-larger-than ------------------------- +--summary-if-larger-than=N +-------------------------- Indicate the maximum size a line may have before it will be summarized. Defaults to `160` if `STDOUT` is a TTY (aka, someone is actually watching the search results), otherwise defaults to `Inf` effectively (indicating no summarization will ever occur). diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index cb8c14c..a327e1a 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -175,14 +175,26 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues my $needle = %n:delete // @specs.shift; meh "Must at least specify a pattern" without $needle; + # Return prelude from -I and -M parameters + my sub prelude() { + my $prelude = ""; + if %n:delete -> \libs { + $prelude = libs.map({"use lib '$_'; "}).join; + } + if %n:delete -> \modules { + $prelude ~= modules.map({"use $_; "}).join; + } + $prelude + } + if $needle.starts-with('/') && $needle.ends-with('/') { $needle .= EVAL; } elsif $needle.starts-with('{') && $needle.ends-with('}') { - $needle = ('-> $_ ' ~ $needle).EVAL; + $needle = (prelude() ~ '-> $_ ' ~ $needle).EVAL; } elsif $needle.starts-with('*.') { - $needle = $needle.EVAL; + $needle = (prelude() ~ $needle).EVAL; } temp $*OUT; @@ -334,7 +346,6 @@ my sub want-lines($needle, @paths, %_ --> Nil) { without $line-number { $line-number = !$no-filename if $human; } - meh-if-unexpected(%_); my int $nr-files; @@ -427,17 +438,17 @@ changed with the C<--file> option All options are optional. Any unexpected options, will cause an exception to be thrown with the unexpected options listed. -=head2 --after-context +=head2 --after-context=N Indicate the number of lines that should be shown B any line that matches. Defaults to B<0>. Will be overridden by a C<--context> argument. -=head2 --before-context +=head2 --before-context=N Indicate the number of lines that should be shown B any line that matches. Defaults to B<0>. Will be overridden by a C<--context> argument. -=head2 --context +=head2 --context=N Indicate the number of lines that should be shown B any line that matches. Defaults to B<0>. Overrides any a C<--after-context> or @@ -450,12 +461,31 @@ When specified with a C value, will show a "N matches in M files" by default, and if the C<:files-with-matches> option is also specified with a C value, will also list the file names with their respective counts. -=head2 --edit +=head2 --edit[=editor] Indicate whether the patterns found should be fed into an editor for inspection and/or changes. Defaults to C. Optionally takes the name of the editor to be used. +=head2 -I=dir + +Indicate the directory that should be searched for Raku module loading. +Only makes sense if the pattern is executable code. + +Please note that contrary to normal use in Raku, the C<=> B be +specified. Also note that you can create a shortcut for most often used +arguments of the C<-I> option: + +=begin code :lang + +$ rak --I=. --save=I. +Saved option '--I.' as: --I='.' + +$ rak --I=lib --save=Ilib +Saved option '--Ilib' as: --I=lib + +=end code + =head2 --no-filename Indicate whether filenames should B be shown. Defaults to C if @@ -467,14 +497,14 @@ Indicate whether the pattern should be highlighted in the line in which it was found. Defaults to C if C<--human> is (implicitly) set to C, else defaults to C. -=head2 --highlight--after +=head2 --highlight--after[=string] Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if C<--highlight> is (implicitly) set to C. Defaults to the empty string if C<--only-matching> is specified with a C value, or to the terminal code to end B otherwise. -=head2 --highlight--before +=head2 --highlight--before[=string] Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if C<--highlight> is (implicitly) set to C. @@ -513,17 +543,25 @@ Indicate whether line numbers should be shown. Defaults to C if C<--human> is (implicitly) set to C and <-h> is B set to C, else defaults to C. +=head2 -M=module + +Indicate the Raku module that should be loaded. Only makes sense if the +pattern is executable code. + +Please note that contrary to normal use in Raku, the C<=> B be +specified. + =head2 --only-matching Indicate whether only the matched pattern should be produced, rather than the line in which the pattern was found. Defaults to C. -=head2 --output-file +=head2 --output-file=filename Indicate the path of the file in which the result of the search should be placed. Defaults to C. -=head2 --pattern +=head2 --pattern=foo Alternative way to specify the pattern to search for. If (implicitly) specified, will assume the first positional parameter specified is @@ -536,7 +574,7 @@ Only makes sense if the specified pattern is a C. Indicates whether the output of the pattern should be applied to the file in which it was found. Defaults to C. -=head2 --save +=head2 --save=name Save all named arguments with the given name in the configuration file (C<~/.rak-config.json>), and exit with a message that these options have @@ -569,7 +607,7 @@ depend on other arguments having been specified. To remove a saved set of named arguments, use C<--save> as the only named argument. -=head2 --summary-if-larger-than +=head2 --summary-if-larger-than=N Indicate the maximum size a line may have before it will be summarized. Defaults to C<160> if C is a TTY (aka, someone is actually watching