-
Notifications
You must be signed in to change notification settings - Fork 1
/
ghoto.go
103 lines (92 loc) · 2.56 KB
/
ghoto.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"github.com/urfave/cli/v2"
"log"
"os"
"runtime"
"strings"
"sync"
"time"
)
type Option struct {
From string
To string
PhotoDir string
VideoDir string
Recursive bool
DryRun bool
Excludes []string
Concurrency int
Force bool
SkipInvalidData bool
Verbose bool
}
const VERSION = "0.1.5"
func main() {
app := &cli.App{
UseShortOptionHandling: true,
Name: "ghoto",
Version: VERSION,
Compiled: time.Now(),
Authors: []*cli.Author{
&cli.Author{
Name: "fukata",
Email: "[email protected]",
},
},
Usage: "Transfer photo(video)",
Flags: []cli.Flag{
&cli.StringFlag{Name: "from", Value: "/path/to/src", Usage: "Source directory"},
&cli.StringFlag{Name: "to", Value: "/path/to/dst", Usage: "Destination directory"},
&cli.StringFlag{Name: "photo-dir", Aliases: []string{"P"}, Value: "photo", Usage: "Destination photo directory"},
&cli.StringFlag{Name: "video-dir", Aliases: []string{"V"}, Value: "video", Usage: "Destination video directory"},
&cli.StringFlag{Name: "exclude", Aliases: []string{"x"}, Value: "", Usage: "Exclude dir/file separate comma."},
&cli.IntFlag{Name: "concurrency", Aliases: []string{"c"}, Value: runtime.NumCPU(), Usage: "Concurrency num."},
&cli.BoolFlag{Name: "recursive", Aliases: []string{"r"}, Usage: "Resursive"},
&cli.BoolFlag{Name: "force", Usage: "Force"},
&cli.BoolFlag{Name: "skip-invalid-data", Usage: "SkipInvalidData"},
&cli.BoolFlag{Name: "dry-run", Usage: "Dry Run"},
&cli.BoolFlag{Name: "verbose, vvv", Usage: "Verbose"},
},
Action: func(c *cli.Context) error {
// options
option := &Option{
c.String("from"),
c.String("to"),
c.String("photo-dir"),
c.String("video-dir"),
c.Bool("recursive"),
c.Bool("dry-run"),
strings.Split(c.String("exclude"), ","),
c.Int("concurrency"),
c.Bool("force"),
c.Bool("skip-invalid-data"),
c.Bool("verbose"),
}
// check path
isDir, err := IsDirectory(option.From)
if err != nil {
log.Fatal(err)
}
if isDir != false {
fmt.Errorf("%s is not found.", option.From)
}
isDir, err = IsDirectory(option.To)
if err != nil {
log.Fatal(err)
}
if isDir != false {
fmt.Errorf("%s is not found.", option.To)
}
// move
var wg sync.WaitGroup
ch := make(chan int, option.Concurrency)
Transfer(&wg, ch, option.From, option)
wg.Wait()
log.Println("done")
return err
},
}
app.Run(os.Args)
}