42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/akamensky/argparse"
|
|
"log"
|
|
"os"
|
|
"fmt"
|
|
)
|
|
|
|
// 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)
|
|
}
|