diff --git a/README.md b/README.md index dff28e8..d025c32 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,21 @@ # Blush +[![PkgGoDev](https://pkg.go.dev/badge/github.com/arsham/dbtools)](https://pkg.go.dev/github.com/arsham/dbtools) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/arsham/dbtools) +[![Build Status](https://github.com/arsham/dbtools/actions/workflows/go.yml/badge.svg)](https://github.com/arsham/dbtools/actions/workflows/go.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -[![GoDoc](https://godoc.org/github.com/arsham/blush?status.svg)](http://godoc.org/github.com/arsham/blush) -[![Build Status](https://travis-ci.org/arsham/blush.svg?branch=master)](https://travis-ci.org/arsham/blush) [![Coverage Status](https://codecov.io/gh/arsham/blush/branch/master/graph/badge.svg)](https://codecov.io/gh/arsham/blush) [![Go Report Card](https://goreportcard.com/badge/github.com/arsham/blush)](https://goreportcard.com/report/github.com/arsham/blush) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4d4d4330fc2e44f18da6d8012d7432b9)](https://www.codacy.com/app/arsham/blush?utm_source=github.com&utm_medium=referral&utm_content=arsham/blush&utm_campaign=Badge_Grade) With Blush, you can highlight matches with any colours of your choice. -![Colored](http://i.imgur.com/RF19HYU.png) +![1](https://user-images.githubusercontent.com/428611/164768864-e9713ac3-0097-4435-8bcb-577dbf7b9931.png) 1. [Install](#install) 2. [Usage](#usage) - - [Match Method](#match-method) - - [Colouring Method](#colouring-method) + - [Note](#note) + - [Normal Mode](#normal-mode) + - [Dropping Unmatched](#dropping-unmatched) - [Piping](#piping) 3. [Arguments](#arguments) - [Notes](#notes) @@ -38,7 +39,25 @@ Make sure you have `go>=1.18` installed. ## Usage -### Match Method +Blush can read from a file or a pipe: + +```bash +$ cat FILENAME | blush -b "print in blue" -g "in green" -g "another green" +$ cat FILENAME | blush "some text" +$ blush -b "print in blue" -g "in green" -g "another green" FILENAME +$ blush "some text" FILENAME +``` + +### Note + +Although this program has a good performance, but performance is not the main +concern. There are other tools you should use if you are searching in large +files. Two examples: + +- [Ripgrep](https://github.com/BurntSushi/ripgrep) +- [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) + +### Normal Mode This method shows matches with the given input: @@ -49,38 +68,23 @@ $ blush -b "first search" -g "second one" -g "and another one" files/paths Any occurrence of `first search` will be in blue, `second one` and `and another one` are in green. -![Colored](http://i.imgur.com/ghUTuva.png) - -### Colouring Method - -With this method all texts are shown, but the matching words are coloured. You -can activate this mode by providing `--colour` or `-C` argument. +![2](https://user-images.githubusercontent.com/428611/164768874-bf687313-c103-449b-bb57-6fdcea51fc5d.png) -![Colored](http://i.imgur.com/3CqzAUd.png) +### Dropping Unmatched -### Piping +By default, unmatched lines are not dropped. But you can use the `-d` flag to +drop them: -Blush can also read from a pipe: - -```bash -$ cat FILENAME | blush -b "print in blue" -g "in green" -g "another green" -$ cat FILENAME | blush "some text" -``` +![3](https://user-images.githubusercontent.com/428611/164768875-c9aa3e47-7db0-454f-8a55-1e2bff332c69.png) ## Arguments -``` -+---------------+----------+------------------------------------------------+ -| Argument | Shortcut | Notes | -+---------------+----------+------------------------------------------------+ -| --colour | -C | Colour, don't drop anything. | -| N/A | -i | Case insensitive matching. | -| N/A | -R | Recursive matching. | -| --no-colour | N/A | Don't colourize matches. | -| --no-color | N/A | Same as --no-colour. | -| --no-filename | -h | Suppress the prefixing of file names on output.| -+---------------+----------+------------------------------------------------+ -``` +| Argument | Shortcut | Notes | +| :------------ | :------- | :---------------------------------------------- | +| N/A | -i | Case insensitive matching. | +| N/A | -R | Recursive matching. | +| --no-filename | -h | Suppress the prefixing of file names on output. | +| --drop | -d | Drop unmatched lines | File names or paths are matched from the end. Any argument that doesn't match any files or paths are considered as regular expression. If regular expressions @@ -91,7 +95,7 @@ provided colour: $ blush -b match1 match2 FILENAME ``` -![Colored](http://i.imgur.com/J6uZPQD.png) +![4](https://user-images.githubusercontent.com/428611/164768879-f9b73b2c-b6bb-4cf5-a98a-e51535fa554a.png) ### Notes @@ -107,7 +111,7 @@ You can provide a number for a colour argument to create a colour group: $ blush -r1 match1 -r2 match2 -r1 match3 FILENAME ``` -![Colored](http://i.imgur.com/cBnyrcy.png) +![5](https://user-images.githubusercontent.com/428611/164768882-5ce57477-e9d5-4170-ac10-731e9391cbee.png) All matches will be shown as blue. But `match1` and `match3` will have a different background colour than `match2`. This means the numbers will create @@ -123,10 +127,8 @@ $ blush -r match1 match3 -g match2 FILENAME You can choose a pre-defined colour, or pass it your own colour with a hash: -``` -+-----------+----------+ -| Argument | Shortcut | -+-----------+----------+ +| Argument | Shortcut | +| :-------- | :------- | | --red | -r | | --green | -g | | --blue | -b | @@ -135,13 +137,11 @@ You can choose a pre-defined colour, or pass it your own colour with a hash: | --yellow | -yl | | --magenta | -mg | | --cyan | -cy | -+-----------+----------+ -``` You can also pass an RGB colour. It can be in short form (--#1b2, -#1b2), or long format (--#11bb22, -#11bb22). -![Colored](http://i.imgur.com/MkBIM9b.png) +![6](https://user-images.githubusercontent.com/428611/164768883-154b4fd9-946f-43eb-b3f5-ede6027c3eda.png) ## Complex Grep @@ -151,15 +151,13 @@ You must put your complex grep into quotations: $ blush -b "^age: [0-9]+" FILENAME ``` -![Colored](http://i.imgur.com/hskdVhe.png) +![7](https://user-images.githubusercontent.com/428611/164768886-5b94b8fa-77e2-4617-80f2-040edce18660.png) ## Suggestions This tool is made to make your experience in terminal a more pleasant. Please feel free to make any suggestions or request features by creating an issue. -Please see [changelog](./CHANGELOG.md) document for newest changes. - ## License Use of this source code is governed by the MIT License. License file can be diff --git a/blush/blush.go b/blush/blush.go index 4347602..cb31986 100644 --- a/blush/blush.go +++ b/blush/blush.go @@ -35,7 +35,7 @@ type Blush struct { Reader io.ReadCloser LineCache uint CharCache uint - NoCut bool // do not cut out non-matched lines. + Drop bool // do not cut out non-matched lines. WithFileName bool closed bool readLineCh chan []byte @@ -123,7 +123,7 @@ func (b *Blush) setup(m mode) error { func (b *Blush) decorate(input string) (string, bool) { str, ok := lookInto(b.Finders, input) - if ok || b.NoCut { + if ok || !b.Drop { var prefix string if b.WithFileName { prefix = fileName(b.Reader) diff --git a/blush/blush_test.go b/blush/blush_test.go index 8327976..49d382c 100644 --- a/blush/blush_test.go +++ b/blush/blush_test.go @@ -16,7 +16,34 @@ import ( "github.com/arsham/blush/internal/reader" ) -func TestWriteToErrors(t *testing.T) { +func TestBlush(t *testing.T) { + t.Parallel() + t.Run("WriteTo", testBlushWriteTo) + t.Run("ClosesReader", testBlushClosesReader) + t.Run("Read", testBlushRead) + t.Run("PrintName", testBlushPrintName) + t.Run("StdinPrintName", testBlushStdinPrintName) + t.Run("PrintFilename", testBlushPrintFilename) + t.Run("ReadContiniously", testBlushReadContiniously) + t.Run("ReadMiddleOfMatch", testBlushReadMiddleOfMatch) + t.Run("ReadComplete", testBlushReadComplete) + t.Run("ReadPartComplete", testBlushReadPartComplete) + t.Run("PartPartOver", testBlushReadPartPartOver) + t.Run("ReadMultiLine", testBlushReadMultiLine) + t.Run("ReadWriteToMode", testBlushReadWriteToMode) +} + +func testBlushWriteTo(t *testing.T) { + t.Parallel() + t.Run("Errors", testBlushWriteToErrors) + t.Run("NoMatch", testBlushWriteToNoMatch) + t.Run("Match", testBlushWriteToMatch) + t.Run("Colour", testBlushWriteToColour) + t.Run("ColourNoCutMode", testBlushWriteToColourNoCutMode) + t.Run("MultipleMatchInOneLine", testBlushWriteToMultipleMatchInOneLine) +} + +func testBlushWriteToErrors(t *testing.T) { t.Parallel() w := &bytes.Buffer{} e := errors.New("something") @@ -38,7 +65,7 @@ func TestWriteToErrors(t *testing.T) { }{ {"no input", &blush.Blush{}, w, 0, reader.ErrNoReader}, {"no writer", &blush.Blush{Reader: getReader()}, nil, 0, blush.ErrNoWriter}, - {"bad writer", &blush.Blush{Reader: getReader(), NoCut: true}, bw, nn, e}, + {"bad writer", &blush.Blush{Reader: getReader(), Drop: true}, bw, nn, e}, } for _, tc := range tcs { @@ -53,7 +80,7 @@ func TestWriteToErrors(t *testing.T) { } } -func TestWriteToNoMatch(t *testing.T) { +func testBlushWriteToNoMatch(t *testing.T) { t.Parallel() pwd, err := os.Getwd() assert.NoError(t, err) @@ -63,6 +90,7 @@ func TestWriteToNoMatch(t *testing.T) { b := &blush.Blush{ Reader: r, Finders: []blush.Finder{blush.NewExact("SHOULDNOTFINDTHISONE", blush.NoColour)}, + Drop: true, } buf := &bytes.Buffer{} n, err := b.WriteTo(buf) @@ -71,7 +99,14 @@ func TestWriteToNoMatch(t *testing.T) { assert.Zero(t, buf.Len()) } -func TestWriteToMatchNoColourPlain(t *testing.T) { +func testBlushWriteToMatch(t *testing.T) { + t.Parallel() + t.Run("Drop", testBlushWriteToMatchDrop) + t.Run("Colour", testBlushWriteToMatchColour) + t.Run("CountColour", testBlushWriteToMatchCountColour) +} + +func testBlushWriteToMatchDrop(t *testing.T) { t.Parallel() match := "TOKEN" pwd, err := os.Getwd() @@ -83,6 +118,7 @@ func TestWriteToMatchNoColourPlain(t *testing.T) { b := &blush.Blush{ Reader: r, Finders: []blush.Finder{blush.NewExact(match, blush.NoColour)}, + Drop: true, } buf := &bytes.Buffer{} @@ -95,7 +131,7 @@ func TestWriteToMatchNoColourPlain(t *testing.T) { assert.NotContains(t, buf.String(), leaveMeHere) } -func TestWriteToMatchColour(t *testing.T) { +func testBlushWriteToMatchColour(t *testing.T) { t.Parallel() match := blush.Colourise("TOKEN", blush.Blue) pwd, err := os.Getwd() @@ -106,6 +142,7 @@ func TestWriteToMatchColour(t *testing.T) { b := &blush.Blush{ Reader: r, Finders: []blush.Finder{blush.NewExact("TOKEN", blush.Blue)}, + Drop: true, } buf := &bytes.Buffer{} @@ -118,7 +155,7 @@ func TestWriteToMatchColour(t *testing.T) { assert.NotContains(t, buf.String(), leaveMeHere) } -func TestWriteToMatchCountColour(t *testing.T) { +func testBlushWriteToMatchCountColour(t *testing.T) { t.Parallel() pwd, err := os.Getwd() assert.NoError(t, err) @@ -148,6 +185,7 @@ func TestWriteToMatchCountColour(t *testing.T) { b := &blush.Blush{ Reader: r, Finders: []blush.Finder{blush.NewExact(tc.name, blush.Red)}, + Drop: true, } buf := &bytes.Buffer{} @@ -161,7 +199,7 @@ func TestWriteToMatchCountColour(t *testing.T) { } } -func TestWriteToMultiColour(t *testing.T) { +func testBlushWriteToColour(t *testing.T) { t.Parallel() two := blush.Colourise("TWO", blush.Magenta) three := blush.Colourise("THREE", blush.Red) @@ -176,6 +214,7 @@ func TestWriteToMultiColour(t *testing.T) { blush.NewExact("TWO", blush.Magenta), blush.NewExact("THREE", blush.Red), }, + Drop: true, } buf := &bytes.Buffer{} @@ -192,7 +231,7 @@ func TestWriteToMultiColour(t *testing.T) { } } -func TestWriteToMultiColourColourMode(t *testing.T) { +func testBlushWriteToColourNoCutMode(t *testing.T) { t.Parallel() two := blush.Colourise("TWO", blush.Magenta) three := blush.Colourise("THREE", blush.Red) @@ -203,7 +242,7 @@ func TestWriteToMultiColourColourMode(t *testing.T) { assert.NoError(t, err) b := &blush.Blush{ Reader: r, - NoCut: true, + Drop: false, Finders: []blush.Finder{ blush.NewExact("TWO", blush.Magenta), blush.NewExact("THREE", blush.Red), @@ -224,7 +263,7 @@ func TestWriteToMultiColourColourMode(t *testing.T) { assert.EqualValues(t, 1, count) } -func TestWriteToMultipleMatchInOneLine(t *testing.T) { +func testBlushWriteToMultipleMatchInOneLine(t *testing.T) { t.Parallel() line1 := "this is an example\n" line2 := "someone should find this line\n" @@ -255,7 +294,7 @@ func TestWriteToMultipleMatchInOneLine(t *testing.T) { assert.EqualValues(t, match, example) } -func TestBlushClosesReader(t *testing.T) { +func testBlushClosesReader(t *testing.T) { t.Parallel() var called bool input := bytes.NewBuffer([]byte("DwgQnpvro5bVvrRwBB")) @@ -274,7 +313,16 @@ func TestBlushClosesReader(t *testing.T) { assert.True(t, called, "didn't close the reader") } -func TestBlushReadOneStream(t *testing.T) { +func testBlushRead(t *testing.T) { + t.Parallel() + t.Run("OneStream", testBlushReadOneStream) + t.Run("TwoStreams", testBlushReadTwoStreams) + t.Run("HalfWay", testBlushReadHalfWay) + t.Run("OnClosed", testBlushReadOnClosed) + t.Run("LongOneLineText", testBlushReadLongOneLineText) +} + +func testBlushReadOneStream(t *testing.T) { t.Parallel() input := bytes.NewBuffer([]byte("one two three four")) match := blush.NewExact("three", blush.Blue) @@ -309,7 +357,7 @@ func TestBlushReadOneStream(t *testing.T) { } } -func TestBlushReadTwoStreams(t *testing.T) { +func testBlushReadTwoStreams(t *testing.T) { t.Parallel() b1 := []byte("one for all\n") b2 := []byte("all for one\n") @@ -335,7 +383,7 @@ func TestBlushReadTwoStreams(t *testing.T) { assert.EqualValues(t, expectStr, buf.String()) } -func TestBlushReadHalfWay(t *testing.T) { +func testBlushReadHalfWay(t *testing.T) { t.Parallel() b1 := []byte("one for all\n") b2 := []byte("all for one\n") @@ -355,7 +403,7 @@ func TestBlushReadHalfWay(t *testing.T) { assert.NoError(t, err) } -func TestBlushReadOnClosed(t *testing.T) { +func testBlushReadOnClosed(t *testing.T) { t.Parallel() b1 := []byte("one for all\n") b2 := []byte("all for one\n") @@ -378,7 +426,7 @@ func TestBlushReadOnClosed(t *testing.T) { assert.Zero(t, n) } -func TestBlushReadLongOneLineText(t *testing.T) { +func testBlushReadLongOneLineText(t *testing.T) { t.Parallel() head := strings.Repeat("a", 10000) tail := strings.Repeat("b", 10000) @@ -399,7 +447,7 @@ func TestBlushReadLongOneLineText(t *testing.T) { assert.Zero(t, n) } -func TestPrintName(t *testing.T) { +func testBlushPrintName(t *testing.T) { t.Parallel() line1 := "line one\n" line2 := "line two\n" @@ -416,6 +464,7 @@ func TestPrintName(t *testing.T) { Reader: r, Finders: []blush.Finder{blush.NewExact("line", blush.NoColour)}, WithFileName: true, + Drop: true, } buf := &bytes.Buffer{} n, err := b.WriteTo(buf) @@ -429,16 +478,15 @@ func TestPrintName(t *testing.T) { } // testing stdin should not print the name -func TestStdinPrintName(t *testing.T) { +func testBlushStdinPrintName(t *testing.T) { t.Parallel() input := "line one" oldStdin := os.Stdin f, err := ioutil.TempFile("", "blush_stdin") assert.NoError(t, err) defer func() { - if err = os.Remove(f.Name()); err != nil { - t.Error(err) - } + err := os.Remove(f.Name()) + assert.NoError(t, err) os.Stdin = oldStdin }() os.Stdin = f @@ -457,7 +505,7 @@ func TestStdinPrintName(t *testing.T) { assert.NotContains(t, buf.String(), f.Name()) } -func TestPrintFileName(t *testing.T) { +func testBlushPrintFilename(t *testing.T) { t.Parallel() p, err := ioutil.TempDir("", "blush_name") assert.NoError(t, err) @@ -466,9 +514,8 @@ func TestPrintFileName(t *testing.T) { f2, err := ioutil.TempFile(p, "blush_name") assert.NoError(t, err) defer func() { - if err = os.RemoveAll(p); err != nil { - t.Error(err) - } + err := os.RemoveAll(p) + assert.NoError(t, err) }() line1 := "line one\n" line2 := "line two\n" @@ -494,6 +541,7 @@ func TestPrintFileName(t *testing.T) { Reader: r, Finders: []blush.Finder{blush.NewExact("line", blush.NoColour)}, WithFileName: tc.withFilename, + Drop: true, } buf := &bytes.Buffer{} n, err := b.WriteTo(buf) @@ -514,7 +562,7 @@ func TestPrintFileName(t *testing.T) { } // reading with a small byte slice until the read is done. -func TestReadContiniously(t *testing.T) { +func testBlushReadContiniously(t *testing.T) { t.Parallel() var ( ret []byte @@ -550,7 +598,7 @@ func TestReadContiniously(t *testing.T) { } } -func TestReadMiddleOfMatch(t *testing.T) { +func testBlushReadMiddleOfMatch(t *testing.T) { t.Parallel() var ( search = "aa this aa" @@ -574,7 +622,7 @@ func TestReadMiddleOfMatch(t *testing.T) { assert.Contains(t, string(ret), "this") } -func TestReadComplete(t *testing.T) { +func testBlushReadComplete(t *testing.T) { t.Parallel() input := "123456789" match := blush.NewExact("1", blush.NoColour) @@ -595,7 +643,7 @@ func TestReadComplete(t *testing.T) { assert.Empty(t, string(bytes.Trim(p, "\x00"))) } -func TestReadPartComplete(t *testing.T) { +func testBlushReadPartComplete(t *testing.T) { t.Parallel() input := "123456789" match := blush.NewExact("1", blush.NoColour) @@ -617,7 +665,7 @@ func TestReadPartComplete(t *testing.T) { assert.EqualValues(t, string(bytes.Trim(p, "\x00")), "456789") } -func TestReadPartPartOver(t *testing.T) { +func testBlushReadPartPartOver(t *testing.T) { t.Parallel() input := "123456789" match := blush.NewExact("1", blush.NoColour) @@ -645,7 +693,7 @@ func TestReadPartPartOver(t *testing.T) { assert.EqualValues(t, string(bytes.Trim(p, "\x00")), "789") } -func TestReadMultiLine(t *testing.T) { +func testBlushReadMultiLine(t *testing.T) { t.Parallel() input := "line1\nline2\nline3\nline4\n" match := blush.NewExact("l", blush.NoColour) @@ -680,7 +728,7 @@ func TestReadMultiLine(t *testing.T) { } } -func TestReadWriteToMode(t *testing.T) { +func testBlushReadWriteToMode(t *testing.T) { t.Parallel() p := make([]byte, 1) r := io.NopCloser(bytes.NewBufferString("input")) diff --git a/cmd/args.go b/cmd/args.go index a6db25a..cdf7cd9 100644 --- a/cmd/args.go +++ b/cmd/args.go @@ -16,7 +16,7 @@ type args struct { matches []string remaining []string finders []blush.Finder - colour bool + cut bool noFilename bool recursive bool insensitive bool @@ -33,7 +33,7 @@ func newArgs(input ...string) (*args, error) { return nil, errShowHelp } a.recursive = a.hasArgs("-R") - a.colour = a.hasArgs("-C", "--colour", "--color") + a.cut = a.hasArgs("-d", "--drop") a.noFilename = a.hasArgs("-h", "--no-filename") a.insensitive = a.hasArgs("-i") diff --git a/cmd/args_test.go b/cmd/args_test.go index 90a9901..271f7dc 100644 --- a/cmd/args_test.go +++ b/cmd/args_test.go @@ -16,19 +16,17 @@ func TestArgs(t *testing.T) { name string input []string wantErr error - colour bool + cut bool noFilename bool recursive bool insensitive bool }{ {name: "help", input: []string{"--help"}, wantErr: errShowHelp}, - {name: "colour", input: []string{"--colour"}, colour: true}, - {name: "colour and help", input: []string{"--colour", "--help"}, wantErr: errShowHelp}, - {name: "colour american", input: []string{"--colour"}, colour: true}, - {name: "colour short", input: []string{"-C"}, colour: true}, + {name: "drop", input: []string{"--drop"}, cut: true}, + {name: "drop short", input: []string{"-d"}, cut: true}, {name: "no filename", input: []string{"-h"}, noFilename: true}, {name: "no filename long", input: []string{"--no-filename"}, noFilename: true}, - {name: "rec", input: []string{"-R"}, recursive: true}, + {name: "recursive", input: []string{"-R"}, recursive: true}, {name: "ins", input: []string{"-i"}, insensitive: true}, {name: "ins rec", input: []string{"-i", "-R"}, insensitive: true, recursive: true}, {name: "rec ins", input: []string{"-R", "-i"}, insensitive: true, recursive: true}, @@ -41,23 +39,24 @@ func TestArgs(t *testing.T) { insensitive: true, recursive: true, noFilename: true, }, { - name: "nofile rec ins colour", input: []string{"-h", "-R", "-i", "-C"}, - insensitive: true, recursive: true, noFilename: true, colour: true, + name: "nofile rec ins drop", input: []string{"-h", "-R", "-i", "-d"}, + insensitive: true, recursive: true, noFilename: true, cut: true, }, } for _, tc := range tcs { tc := tc t.Run(tc.name, func(t *testing.T) { + tc.input = append(tc.input, "*") a, err := newArgs(tc.input...) if tc.wantErr != nil { assert.True(t, errors.Is(err, tc.wantErr)) - } - if err != nil { assert.Nil(t, a) return } - assert.Equal(t, tc.colour, a.colour) + assert.NoError(t, err) + assert.NotNil(t, a) + assert.Equal(t, tc.cut, a.cut) assert.Equal(t, tc.noFilename, a.noFilename) assert.Equal(t, tc.recursive, a.recursive) assert.Equal(t, tc.insensitive, a.insensitive) diff --git a/cmd/main.go b/cmd/main.go index ecbbb39..aa8b5ac 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -62,7 +62,7 @@ func GetBlush(input []string) (*blush.Blush, error) { return &blush.Blush{ Finders: a.finders, Reader: r, - NoCut: a.colour, + Drop: a.cut, WithFileName: !a.noFilename, }, nil } diff --git a/cmd/main_test.go b/cmd/main_test.go index 351e686..6a468b9 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -69,30 +69,18 @@ func TestMainMatch(t *testing.T) { } } -func TestMainMatchNoCut(t *testing.T) { +func TestMainMatchCut(t *testing.T) { matches := []string{"TOKEN", "ONE", "TWO", "THREE", "FOUR"} pwd, err := os.Getwd() assert.NoError(t, err) location := path.Join(pwd, "../blush/testdata") - tcs := []struct { - name, input string - }{ - {"short", "-C"}, - {"long", "--colour"}, - {"long american", "--colour"}, - } - for _, tc := range tcs { - tc := tc - t.Run(tc.name, func(t *testing.T) { - stdout, stderr := setup(t, fmt.Sprintf("%s -b %s %s", tc.input, leaveMeHere, location)) - cmd.Main() - assert.Empty(t, stderr.String()) - assert.NotEmpty(t, stdout.String()) - for _, s := range matches { - assert.Contains(t, stdout.String(), s) - } - }) + stdout, stderr := setup(t, fmt.Sprintf("-b %s %s", leaveMeHere, location)) + cmd.Main() + assert.Empty(t, stderr.String()) + assert.NotEmpty(t, stdout.String()) + for _, s := range matches { + assert.Contains(t, stdout.String(), s) } } diff --git a/cmd/usage.go b/cmd/usage.go index fbb8c34..6097b82 100644 --- a/cmd/usage.go +++ b/cmd/usage.go @@ -32,9 +32,8 @@ Stock Colours: -cy, --cyan Control arguments: - -C, --colour Don't drop unmatched lines. + -d, --drop Drop unmatched lines. -i Case insensitive match. - --no-colour, --no-color Don't colourise the output. -h, --no-filename Suppress the prefixing of file names on output. Multi match colouring: