diff options
| author | ayyansea <ayyansea@gmail.com> | 2024-12-04 22:02:42 +0300 |
|---|---|---|
| committer | ayyansea <ayyansea@gmail.com> | 2024-12-04 22:02:42 +0300 |
| commit | f79d809ecbed2959c1e854c7b8adfbf425823099 (patch) | |
| tree | 7e59145b39f2936dafce1b59c4ede9f0eb446d55 /cmd/uptfs | |
| parent | e2379a3098c01b0400ff2d46b1398222bb6a36fb (diff) | |
feat: add OutputFile argument and corresponding feature
Diffstat (limited to 'cmd/uptfs')
| -rw-r--r-- | cmd/uptfs/main.go | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/cmd/uptfs/main.go b/cmd/uptfs/main.go index 9040e0b..7c3531e 100644 --- a/cmd/uptfs/main.go +++ b/cmd/uptfs/main.go @@ -19,6 +19,7 @@ var args struct { ConfigFile string `arg:"-c" help:"path to config file" default:""` Verbose bool `arg:"-v" help:"toggle verbose (debug) mode"` InputFile string `arg:"-i" help:"name of input file to read text from"` + OutputFile string `arg:"-o" help:"name of output file to write text to"` Filter []string `arg:"-f,separate" help:"name of a filter that will be applied to text, can be specified multiple times"` } @@ -141,14 +142,34 @@ func main() { tokenlist.Clear() } - result := "" + if len(args.OutputFile) > 0 { + var result []byte - for _, elem := range tokenizedInputSlice { - for current := elem.GetHead(); current != nil; current = current.GetNextToken() { - result = result + current.GetContent() + outputFilePath, _ := filepath.Abs(args.OutputFile) + os.Create(outputFilePath) + + for _, elem := range tokenizedInputSlice { + for current := elem.GetHead(); current != nil; current = current.GetNextToken() { + result = append(result, []byte(current.GetContent())...) + } + result = append(result, []byte("\n")...) + f, _ := os.OpenFile(outputFilePath, os.O_APPEND|os.O_WRONLY, 0644) + defer f.Close() + if _, err = f.Write(result); err != nil { + panic(err) + } + result = []byte("") + } + } else { + var result string + + for _, elem := range tokenizedInputSlice { + for current := elem.GetHead(); current != nil; current = current.GetNextToken() { + result = result + current.GetContent() + } + fmt.Println(result) + result = "" } - fmt.Println(result) - result = "" } slog.Debug("uptfs finished") |
