-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
78 lines (69 loc) · 1.46 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package s3ry
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/briandowns/spinner"
)
// PromptItems struct for promptui
type PromptItems struct {
Key int
Val string
Size int64
LastModified time.Time
Tag string
}
// spinner var
var sp = spinner.New(spinner.CharSets[34], 100*time.Millisecond)
// sps Starts spinner
func sps(label string) {
fmt.Println(label)
sp.Start()
}
// spe end spinner
func spe() {
sp.Stop()
}
// checkLocalExists check localFile
func checkLocalExists(objectKey string) {
filename := filepath.Base(objectKey)
_, err := os.Stat(filename)
if err == nil {
var overlide string
fmt.Println(i18nPrinter.Sprintf("The file exists. Overwrite? File name:% s, [Yy] / [Nn]", filename))
fmt.Scan(&overlide)
if overlide != "y" && overlide != "Y" {
log.Fatal("End processing")
}
}
}
// awsErrorPrint print Error for AWS
func awsErrorPrint(err error) {
if aerr, ok := err.(awserr.Error); ok {
log.Fatal(aerr.Error())
}
log.Fatal(err.Error())
}
// dirwalk get fileList
func dirwalk(dir string) []string {
if dir == "" {
dir = "./"
}
files, err := ioutil.ReadDir(dir)
if err != nil {
log.Fatal(err.Error())
}
var paths []string
for _, file := range files {
if file.IsDir() {
paths = append(paths, dirwalk(filepath.Join(dir, file.Name()))...)
continue
}
paths = append(paths, filepath.Join(dir, file.Name()))
}
return paths
}