-
Notifications
You must be signed in to change notification settings - Fork 370
/
remove.go
55 lines (45 loc) · 1.35 KB
/
remove.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
package cmd
import (
"os"
"path/filepath"
"sync"
"github.com/spf13/cobra"
"github.com/vbauerster/mpb"
"github.com/Shopify/themekit/kit"
)
var removeCmd = &cobra.Command{
Use: "remove <filenames>",
Short: "Remove theme file(s) from shopify",
Long: `Remove will delete all specified files from shopify servers.
For more documentation please see http://shopify.github.io/themekit/commands/#remove
`,
RunE: forEachClient(remove),
}
func remove(client kit.ThemeClient, filenames []string, wg *sync.WaitGroup) {
defer wg.Done()
if client.Config.ReadOnly {
kit.LogErrorf("[%s]environment is reaonly", kit.GreenText(client.Config.Environment))
return
}
bar := newProgressBar(len(filenames), client.Config.Environment)
for _, filename := range filenames {
wg.Add(1)
go performRemove(client, kit.Asset{Key: filename}, bar, wg)
}
}
func performRemove(client kit.ThemeClient, asset kit.Asset, bar *mpb.Bar, wg *sync.WaitGroup) {
defer wg.Done()
defer incBar(bar)
resp, err := client.DeleteAsset(asset)
if err != nil {
kit.LogErrorf("[%s]%s", kit.GreenText(client.Config.Environment), err)
} else if verbose {
kit.Printf(
"[%s] Successfully removed file %s from %s",
kit.GreenText(client.Config.Environment),
kit.BlueText(asset.Key),
kit.YellowText(resp.Host),
)
os.Remove(filepath.Join(client.Config.Directory, asset.Key))
}
}