From b3c0f0d863ae80cde48a7c0462d9b784b6193c6e Mon Sep 17 00:00:00 2001 From: ayyansea Date: Mon, 18 Nov 2024 22:35:47 +0300 Subject: feat: add some more useful arguments --- cmd/uptfs/main.go | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'cmd/uptfs') diff --git a/cmd/uptfs/main.go b/cmd/uptfs/main.go index 4ecb045..c7b98e1 100644 --- a/cmd/uptfs/main.go +++ b/cmd/uptfs/main.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "strings" "github.com/alexflint/go-arg" @@ -14,13 +15,48 @@ import ( ) var args struct { - Foo string `help:"it's a foo"` - Bar bool `help:"it's a bar"` + ConfigFile string `arg:"-c" help:"path to config file" default:""` + InputFile string `arg:"-i" help:"path to input file" default:""` + OutputFile string `arg:"-o" help:"path to output file" default:""` + Filters []string `arg:"-f" help:"list of filters" default:""` +} + +func errExit(err error) { + fmt.Println(err) + os.Exit(1) } func main() { arg.MustParse(&args) - fmt.Println(args.Foo, args.Bar) + + var configFilePath, inputFilePath, outFilePath string + var err error + + if args.ConfigFile != "" { + configFilePath, err = filepath.Abs(args.ConfigFile) + } + if err != nil { + errExit(err) + } + + if args.InputFile != "" { + inputFilePath, err = filepath.Abs(args.InputFile) + } + if err != nil { + errExit(err) + } + + if args.OutputFile != "" { + outFilePath, err = filepath.Abs(args.OutputFile) + } + if err != nil { + errExit(err) + } + + fmt.Printf("%v %v %v\n", + configFilePath, + inputFilePath, + outFilePath) scanner := bufio.NewScanner(os.Stdin) scanner.Scan() @@ -52,9 +88,4 @@ func main() { current.SetContent(lowercaseFilter.Filter(current.GetContent())) current.SetContent(uppercaseFilter.Filter(current.GetContent())) } - - head := linkedTokens.GetHead() - tail := linkedTokens.GetTail() - fmt.Println("Head: ", head.GetContent()) - fmt.Println("Tail: ", tail.GetContent()) } -- cgit v1.2.3