summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorayyansea <ayyansea@gmail.com>2024-12-04 21:47:02 +0300
committerayyansea <ayyansea@gmail.com>2024-12-04 21:47:02 +0300
commite2379a3098c01b0400ff2d46b1398222bb6a36fb (patch)
tree4ec1905dc7acee9e8c13d0d4e0900e38e9b2f048
parent64f06f1b71ec91f60f85f3cf6f7adb85a9892a6f (diff)
feat: add InputFile argument and corresponding feature
-rw-r--r--cmd/uptfs/main.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/cmd/uptfs/main.go b/cmd/uptfs/main.go
index a088b52..9040e0b 100644
--- a/cmd/uptfs/main.go
+++ b/cmd/uptfs/main.go
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"slices"
+ "strings"
"github.com/alexflint/go-arg"
"github.com/ayyansea/uptfs/internal/config"
@@ -17,6 +18,7 @@ import (
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"`
Filter []string `arg:"-f,separate" help:"name of a filter that will be applied to text, can be specified multiple times"`
}
@@ -45,10 +47,26 @@ func main() {
config.Filters = append(config.Filters, args.Filter...)
+ var scanner *bufio.Scanner
+ var inputFileData []byte
var inputStrings []string
- scanner := bufio.NewScanner(os.Stdin)
- for scanner.Scan() {
- inputStrings = append(inputStrings, scanner.Text())
+
+ if len(args.InputFile) > 0 {
+ inputFilePath, _ := filepath.Abs(args.InputFile)
+ inputFileData, err = os.ReadFile(inputFilePath)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ scanner = bufio.NewScanner(strings.NewReader(string(inputFileData)))
+ for scanner.Scan() {
+ inputStrings = append(inputStrings, scanner.Text())
+ }
+ } else {
+ scanner = bufio.NewScanner(os.Stdin)
+ for scanner.Scan() {
+ inputStrings = append(inputStrings, scanner.Text())
+ }
}
additionalDelimeters := []string{",", ".", " "}