-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
96 lines (88 loc) · 3.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"flag"
"fmt"
"os"
"strings"
app "github.com/hahwul/gee/pkg/gee"
model "github.com/hahwul/gee/pkg/model"
printing "github.com/hahwul/gee/pkg/printing"
"github.com/logrusorgru/aurora"
)
func main() {
// Commandline parse
versionOption := flag.Bool("version", false, "Version of gee")
appendOption := flag.Bool("append", false, "Append mode for files")
chunkedLineOption := flag.Int("chunked", 0, "Chuked files from line (e.g output / output_1 / output_2)")
withLineOption := flag.Bool("with-line", false, "With line number (colorize blue)")
withTimeOption := flag.Bool("with-time", false, "With timestamp (colorize green)")
prefixOption := flag.String("prefix", "", "Prefix string")
suffixOption := flag.String("suffix", "", "Suffix string")
rmnlOption := flag.Bool("rmnl", false, "Remove newline(\\r\\n)")
distributeOption := flag.Bool("distribute", false, "Distribution to files")
colorOption := flag.Bool("uncolor", false, "Uncolorize stdout")
regexOption := flag.String("grep", "", "Greping with Regular Expression (like grep)")
regexvOption := flag.String("grepv", "", "Inverse greping with Regular Expression (like grep -v)")
findOption := flag.String("find", "", "Find string in line (colorize red)")
replaceOption := flag.String("replace", "", "Replace string in line with '-find' option")
splitOption := flag.String("split", "", "Split string within line. (to line , to table, to md-table)")
formatOption := flag.String("format", "line", "Change output format (json, md-table, html-table)")
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 (e.g: -inject='This is %%INJECT%% line!')")
withLCOption := flag.Bool("with-lc", false, "With letters count (colorize magenta)")
// Custom usage
flag.Usage = func() {
printing.Banner()
fmt.Fprintf(os.Stderr, aurora.White("Usage: %s [flags] [file1] [file2] ...\n").String(), os.Args[0])
fmt.Fprintf(os.Stderr, "(If you do not specify a file, only stdout is output)\n\n")
fmt.Fprintf(os.Stderr, aurora.White("Flags:\n").String())
flag.PrintDefaults()
}
// Flag parse
flag.Parse()
// Show version
if *versionOption {
fmt.Println(printing.VERSION)
return
}
// Finding file value
var files []string
args := flag.Args()
for _, v := range args {
if !strings.HasPrefix(v, "-") {
files = append(files, v)
}
}
// Set Options
options := model.Options{
Files: files,
Append: *appendOption,
ChunkedLine: *chunkedLineOption,
WithLine: *withLineOption,
WithTimestamp: *withTimeOption,
Prefix: *prefixOption,
Suffix: *suffixOption,
RemoveNewLine: *rmnlOption,
Distribute: *distributeOption,
Regex: *regexOption,
RegexV: *regexvOption,
Replace: *replaceOption,
Find: *findOption,
Color: !*colorOption,
Split: *splitOption,
Format: *formatOption,
Debug: *debugOption,
Reverse: *reverseOption,
Uniq: *uniqOption,
Inject: *injectOption,
WithLettersCount: *withLCOption,
}
if *debugOption {
printing.DebugMsg("MSG", "Running on Debug mode", options.Debug)
printing.DebugMsg("FILES", files, options.Debug)
}
// Running gee app
app.Gee(options)
}