Browse Source

Merge pull request #1 from kPherox/remove-old-files

kPherox 4 years ago
parent
commit
647ac9f76a
3 changed files with 10 additions and 2 deletions
  1. 5 0
      masto-emoji-pack.go
  2. 4 1
      options.go
  3. 1 1
      version.go

+ 5 - 0
masto-emoji-pack.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"os"
 	"path/filepath"
 	"strings"
 )
@@ -48,6 +49,10 @@ func saveEmojiList(domain string, opts Options, c chan Result) {
 
 	out := filepath.Join(opts.OutputDir, strings.Replace(domain, ".", "_", -1))
 
+	if !opts.KeepOld {
+		os.RemoveAll(out)
+	}
+
 	if !opts.Split {
 		p := NewEmojiPack()
 		p.SetFiles(es)

+ 4 - 1
options.go

@@ -14,6 +14,7 @@ type Options struct {
 	Version   bool
 	Servers   []string
 	Split     bool
+	KeepOld   bool
 	OutputDir string
 }
 
@@ -23,7 +24,7 @@ func Help() {
 }
 
 func Version() {
-    fmt.Printf("masto-emoji-pack v%s\n", VERSION)
+	fmt.Printf("masto-emoji-pack v%s\n", VERSION)
 	os.Exit(0)
 }
 
@@ -44,6 +45,7 @@ func parseOptions() (options Options) {
 	help := getopt.BoolLong("help", 'h', "show help message")
 	version := getopt.BoolLong("version", 'v', "show version info")
 	split := getopt.BoolLong("split", 's', "split emoji pack via category")
+	keepOld := getopt.BoolLong("keep-old", 'k', "keep old files")
 	dir := getopt.StringLong("path", 'p', "/tmp", "generate emoji pack directory", "PATH")
 
 	Parse()
@@ -53,6 +55,7 @@ func parseOptions() (options Options) {
 		Version:   *version,
 		Servers:   getopt.Args(),
 		Split:     *split,
+		KeepOld:   *keepOld,
 		OutputDir: filepath.Clean(*dir),
 	}
 

+ 1 - 1
version.go

@@ -1,3 +1,3 @@
 package main
 
-const VERSION="1.0.0"
+const VERSION = "1.0.0"