-
Notifications
You must be signed in to change notification settings - Fork 363
/
remove.go
45 lines (38 loc) · 1.08 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
package cmd
import (
"os"
"path/filepath"
"sync"
"github.com/spf13/cobra"
"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()
for _, filename := range filenames {
wg.Add(1)
go performRemove(client, kit.Asset{Key: filename}, wg)
}
}
func performRemove(client kit.ThemeClient, asset kit.Asset, wg *sync.WaitGroup) {
defer wg.Done()
resp, err := client.DeleteAsset(asset)
if err != nil {
kit.LogErrorf("[%s]%s", kit.GreenText(client.Config.Environment), err)
} else {
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))
}
}