From db26db4567e45aa5751bf9a340626bc874aefa3a Mon Sep 17 00:00:00 2001 From: hahwul Date: Thu, 14 Oct 2021 00:17:15 +0900 Subject: [PATCH] (Close #37) Add -inject flag Signed-off-by: hahwul --- main.go | 2 ++ pkg/gee/string.go | 4 ++++ pkg/model/options.go | 1 + 3 files changed, 7 insertions(+) diff --git a/main.go b/main.go index f749534..2edd8b3 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ func main() { debugOption := flag.Bool("debug", false, "Show debug message!") reverseOption := flag.Bool("reverse", false, "Reverse string in line") uniqOption := flag.Bool("uniq", false, "Remove duplicated line") + injectOption := flag.String("inject", "", "Inject stdin into the format of the factor value (This is %%INJECT%% line!)") // Custom usage flag.Usage = func() { @@ -82,6 +83,7 @@ func main() { Debug: *debugOption, Reverse: *reverseOption, Uniq: *uniqOption, + Inject: *injectOption, } if *debugOption { printing.DebugMsg("MSG", "Running on Debug mode", options.Debug) diff --git a/pkg/gee/string.go b/pkg/gee/string.go index 273661b..a7f32ba 100644 --- a/pkg/gee/string.go +++ b/pkg/gee/string.go @@ -32,6 +32,10 @@ func StringProc(l string, stdLine int, options model.Options) (string, string) { } } + if strings.Contains(options.Inject, "%%INJECT%%") { + result = strings.Replace(options.Inject, "%%INJECT%%", result, -1) + } + if options.WithLine { result = au.BrightBlue("["+strconv.Itoa(stdLine)+"] ").String() + result resultPlain = "[" + strconv.Itoa(stdLine) + "] " + resultPlain diff --git a/pkg/model/options.go b/pkg/model/options.go index 4ff2d02..bb3e3c4 100644 --- a/pkg/model/options.go +++ b/pkg/model/options.go @@ -22,4 +22,5 @@ type Options struct { Debug bool Reverse bool Uniq bool + Inject string }