diff --git a/Changes b/Changes index ed67176..517ad4b 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,11 @@ Revision history for App-Rak {{$NEXT}} +0.0.13 2022-07-17T10:17:34+02:00 + - Fix issue when there was no config file available + - Remove mentions of now removed option names + - Allow editor to be named with --edit + 0.0.12 2022-07-16T22:17:25+02:00 - Process named arg substitutions in the order they are specified - Remove all aliases for each option: each option can only be accessed diff --git a/META6.json b/META6.json index e74b904..1f7e17a 100644 --- a/META6.json +++ b/META6.json @@ -31,5 +31,5 @@ ], "test-depends": [ ], - "version": "0.0.12" + "version": "0.0.13" } diff --git a/README.md b/README.md index 5e23d53..56f758a 100644 --- a/README.md +++ b/README.md @@ -54,22 +54,22 @@ All options are optional. Any unexpected options, will cause an exception to be --after-context --------------- -Indicate the number of lines that should be shown **after** any line that matches. Defaults to **0**. Will be overridden by a `-C` or `--context` argument. +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 ---------------- -Indicate the number of lines that should be shown **before** any line that matches. Defaults to **0**. Will be overridden by a `-C` or `--context` argument. +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 --------- -Indicate the number of lines that should be shown **around** any line that matches. Defaults to **0**. Overrides any a `-A`, `--after`, `--after-context`, `-B`, `--before` or `--before-context` argument. argument. +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. --edit ------ -Indicate whether the patterns found should be fed into an editor for inspection and/or changes. Defaults to `False`. +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. --no-filename ------------- @@ -84,12 +84,12 @@ Indicate whether the pattern should be highlighted in the line in which it was f --highlight--after ------------------ -Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitely) set to `True`. Defaults to the empty string if `-o` or `--only-matching` is specified with a `True` value, or to the terminal code to end **bold** otherwise. +Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitely) 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 ------------------- -Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitely) set to `True`. Defaults to a space if `-o` or `--only-matching` is specified with a `True` value, or to the terminal code to start **bold** otherwise. +Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitely) 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. --human ------- diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index b1c95b9..1d0c472 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -107,7 +107,7 @@ use CLI::Version:ver<0.0.3>:auth $?DISTRIBUTION, &MAIN; # Main handler my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues - my %config := from-json($config-file.slurp) if $config-file.e; + my %config := $config-file.e ?? from-json($config-file.slurp) !! { } # Saving config if %n:delete -> $option { @@ -133,8 +133,8 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues my @strange; for original-nameds() -> $option { my $value := %n{$option}; - if Bool.ACCEPTS($value) { - if %config{$option} -> %adding { + if %config{$option} -> %adding { + if Bool.ACCEPTS($value) { %n{$option}:delete; if $value { %n{.key} = .value unless %n{.key}:exists for %adding; @@ -143,12 +143,12 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues %n{.key}:delete for %adding; } } - } - else { - @strange.push: "--$option"; + else { + @strange.push: "--$option"; + } } } - meh "These options Must be flags, did you mean: @strange[] ?" if @strange; + meh "These options must be flags, did you mean: @strange[] ?" if @strange; my $needle = %n:delete // @specs.shift; meh "Must at least specify a pattern" without $needle; @@ -182,8 +182,8 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues !! @specs.&hyperize(1, %n).map({ paths($_, |%additional).Slip }) ).sort(*.fc); - %n:delete - ?? go-edit-files($needle, @paths, %n) + (my $editor := %n:delete) + ?? go-edit-files($editor, $needle, @paths, %n) !! is-simple-Callable($needle) && (%n:delete) ?? replace-files($needle, @paths, %n) !! (%n:delete) @@ -191,7 +191,9 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues !! want-lines($needle, @paths, %n); } -my sub go-edit-files($needle, @paths, %_ --> Nil) { +my sub go-edit-files($editor, $needle, @paths, %_ --> Nil) { + CATCH { meh .message } + my $files-only := %_:delete; my %ignore := named-args %_, :ignorecase, @@ -201,14 +203,15 @@ my sub go-edit-files($needle, @paths, %_ --> Nil) { meh-if-unexpected(%_); - edit-files $files-only + edit-files ($files-only ?? files-containing($needle, @paths, :files-only, |%additional) !! files-containing($needle, @paths, |%additional).map: { my $path := .key; .value.map({ $path => .key + 1 => columns(.value, $needle, |%ignore).head }).Slip - } + }), + :editor(Bool.ACCEPTS($editor) ?? Any !! $editor) } my sub replace-files($needle, @paths, %_ --> Nil) { @@ -396,26 +399,24 @@ to be thrown with the unexpected options listed. =head2 --after-context Indicate the number of lines that should be shown B any line that -matches. Defaults to B<0>. Will be overridden by a C<-C> or C<--context> -argument. +matches. Defaults to B<0>. Will be overridden by a C<--context> argument. =head2 --before-context Indicate the number of lines that should be shown B any line that -matches. Defaults to B<0>. Will be overridden by a C<-C> or C<--context> -argument. +matches. Defaults to B<0>. Will be overridden by a C<--context> argument. =head2 --context Indicate the number of lines that should be shown B any line that -matches. Defaults to B<0>. Overrides any a C<-A>, C<--after>, -C<--after-context>, C<-B>, C<--before> or C<--before-context> argument. -argument. +matches. Defaults to B<0>. Overrides any a C<--after-context> or +C<--before-context> arguments. =head2 --edit Indicate whether the patterns found should be fed into an editor for -inspection and/or changes. Defaults to C. +inspection and/or changes. Defaults to C. Optionally takes the +name of the editor to be used. =head2 --no-filename @@ -432,15 +433,15 @@ C, else defaults to C. Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if C<--highlight> is (implicitely) set to C. -Defaults to the empty string if C<-o> or C<--only-matching> is specified -with a C value, or to the terminal code to end B otherwise. +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 Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if C<--highlight> is (implicitely) set to C. -Defaults to a space if C<-o> or C<--only-matching> is specified with a -C value, or to the terminal code to start B otherwise. +Defaults to a space if C<--only-matching> is specified with a C value, +or to the terminal code to start B otherwise. =head2 --human