diff --git a/README.md b/README.md index 8854f73..035da05 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,26 @@ git clone https://gitea.thegux.fr/rmanach/packer * Build the binary ```bash make build +``` + +## Usage + +### Arguments +* **-r** (**required**) : filename regex +* **-o** (**required**) : full path of the zip archive output +* **-d** (**optional**) : full path of the directory to check +* **-x** (**optional**) : remove original files after successful zip + +```bash +# template usage +./packer -r -o + +# zip '.log' files located in '/root/logs' directory +# 'root_log.zip' will be created in the current directory +./packer -r ^.*\.log$ -d /root/logs -o root_logs.zip + +# zip '.doc' files located in the current directory +# the zip archive will be create in '/home/tutu/doc/' +# all '.doc' files will be removed after successful zip +./packer -r ^.*\.doc$ -o /home/tutu/doc/root_log.zip -x ``` \ No newline at end of file diff --git a/main.go b/main.go index 5fe7deb..a62e35f 100644 --- a/main.go +++ b/main.go @@ -190,8 +190,13 @@ func main() { log.Printf("looking for file '%s' in '%s' ...", rd.String(), directory) files, err := getFilesFromDirectoryPath(directory, rd) - // generating zip archive log.Printf("files found : %d", len(files)) + if len(files) == 0 { + message := fmt.Sprintf("no file found in the directory : %s with the regex : %s", directory, regex) + log.Fatal(message) + } + + // generating zip archive err = generateZip(outputPath, files) // check if errors occured during zip