Skip to content

Commit a0cc564

Browse files
committed
Address comments; consts, split bundle commands into files
1 parent dc4360f commit a0cc564

File tree

8 files changed

+331
-287
lines changed

8 files changed

+331
-287
lines changed

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ check: cross build_e2e_all $(HOST_BUILD_DIR)/crc-embedder test cross-lint vendor
9191
install: $(SOURCES)
9292
go install -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
9393

94-
.PHONY: build
95-
build: $(SOURCES)
96-
go build -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
97-
9894
$(BUILD_DIR)/macos-amd64/crc: $(SOURCES)
9995
GOOS=darwin GOARCH=amd64 go build -tags "$(BUILDTAGS)" -ldflags="$(LDFLAGS)" -o $@ $(GO_EXTRA_BUILDFLAGS) ./cmd/crc
10096

cmd/crc/cmd/bundle/bundle.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ func GetBundleCmd(config *config.Config) *cobra.Command {
99
bundleCmd := &cobra.Command{
1010
Use: "bundle SUBCOMMAND [flags]",
1111
Short: "Manage CRC bundles",
12-
Long: "Manage CRC bundles",
12+
Long: "Manage CRC bundles, including downloading, listing, and cleaning up cached bundles.",
1313
Run: func(cmd *cobra.Command, _ []string) {
1414
_ = cmd.Help()
1515
},
1616
}
1717
bundleCmd.AddCommand(getGenerateCmd(config))
1818
bundleCmd.AddCommand(getDownloadCmd(config))
19+
bundleCmd.AddCommand(getListCmd(config))
20+
bundleCmd.AddCommand(getClearCmd())
21+
bundleCmd.AddCommand(getPruneCmd())
1922
return bundleCmd
2023
}

cmd/crc/cmd/bundle/clear.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package bundle
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
8+
"github.com/crc-org/crc/v2/pkg/crc/constants"
9+
"github.com/crc-org/crc/v2/pkg/crc/logging"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func getClearCmd() *cobra.Command {
14+
return &cobra.Command{
15+
Use: "clear",
16+
Short: "Clear cached CRC bundles",
17+
Long: "Delete all downloaded CRC bundles from the cache directory.",
18+
RunE: func(cmd *cobra.Command, args []string) error {
19+
return runClear()
20+
},
21+
}
22+
}
23+
24+
func runClear() error {
25+
cacheDir := constants.MachineCacheDir
26+
if _, err := os.Stat(cacheDir); os.IsNotExist(err) {
27+
logging.Infof("Cache directory %s does not exist", cacheDir)
28+
return nil
29+
}
30+
31+
files, err := os.ReadDir(cacheDir)
32+
if err != nil {
33+
return err
34+
}
35+
36+
cleared := false
37+
for _, file := range files {
38+
if strings.HasSuffix(file.Name(), ".crcbundle") {
39+
filePath := filepath.Join(cacheDir, file.Name())
40+
logging.Infof("Deleting %s", filePath)
41+
if err := os.RemoveAll(filePath); err != nil {
42+
logging.Errorf("Failed to remove %s: %v", filePath, err)
43+
}
44+
cleared = true
45+
}
46+
}
47+
48+
if !cleared {
49+
logging.Infof("No bundles found in %s", cacheDir)
50+
} else {
51+
logging.Infof("Cleared cached bundles in %s", cacheDir)
52+
}
53+
return nil
54+
}
55+

0 commit comments

Comments
 (0)