diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7456fbf --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g= +github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= diff --git a/main.go b/main.go index 5ca719b..4a7cdde 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,41 @@ package main import ( + "github.com/akamensky/argparse" "log" + "os" + "fmt" ) -func main() { - log.Printf("packer") +// parseArguments - get needed arguments to launch the `packer` +// returns 3 strings : +// * regex +// * outputPath +// * directory +func parseArguments() (string, string, string, error) { + parser := argparse.NewParser("packer", "packer - zip file where filenames match with a regex") + var err error + + regex := parser.String("r", "regex", &argparse.Options{Required: true, Help: "filename Regex"}) + outputPath := parser.String("o", "output-path", &argparse.Options{Required: true, Help: "zip output path (including zip name)"}) + directory := parser.String("d", "directory", &argparse.Options{Required: false, Help: "root directory to check files", Default: "."}) + + parseError := parser.Parse(os.Args) + if parseError != nil { + err = fmt.Errorf("parsing error: %s", parseError) + } + + return *regex, *outputPath, *directory, err +} + +func main() { + + regex, directory, outputPath, err := parseArguments() + + if err != nil { + log.Fatal("error while parsing args : ", err) + } + + log.Printf("looking for file '%s' in '%s' ...", regex, directory) + log.Printf("files zipped in %s", outputPath) }