Skip to content

Commit

Permalink
(Close #37) Add -inject flag
Browse files Browse the repository at this point in the history
Signed-off-by: hahwul <[email protected]>
  • Loading branch information
hahwul committed Oct 13, 2021
1 parent 73fbbf7 commit db26db4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/gee/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/model/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ type Options struct {
Debug bool
Reverse bool
Uniq bool
Inject string
}

0 comments on commit db26db4

Please sign in to comment.