github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/cache_clean_linux.go (about) 1 // Copyright (c) 2018-2019, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package cli 7 8 import ( 9 "os" 10 11 "github.com/spf13/cobra" 12 "github.com/sylabs/singularity/docs" 13 "github.com/sylabs/singularity/internal/app/singularity" 14 "github.com/sylabs/singularity/internal/pkg/sylog" 15 ) 16 17 var ( 18 cleanAll bool 19 cacheCleanTypes []string 20 cacheName string 21 ) 22 23 func init() { 24 CacheCleanCmd.Flags().SetInterspersed(false) 25 26 CacheCleanCmd.Flags().BoolVarP(&cleanAll, "all", "a", false, "clean all cache (will override all other options)") 27 CacheCleanCmd.Flags().SetAnnotation("all", "envkey", []string{"ALL"}) 28 29 CacheCleanCmd.Flags().StringSliceVarP(&cacheCleanTypes, "type", "T", []string{"blob"}, "clean cache type, choose between: library, oci, and blob") 30 CacheCleanCmd.Flags().SetAnnotation("type", "envkey", []string{"TYPE"}) 31 32 CacheCleanCmd.Flags().StringVarP(&cacheName, "name", "N", "", "specify a container cache to clean (will clear all cache with the same name)") 33 CacheCleanCmd.Flags().SetAnnotation("name", "envkey", []string{"NAME"}) 34 } 35 36 // CacheCleanCmd : is `singularity cache clean' and will clear your local singularity cache 37 var CacheCleanCmd = &cobra.Command{ 38 Args: cobra.ExactArgs(0), 39 DisableFlagsInUseLine: true, 40 Run: func(cmd *cobra.Command, args []string) { 41 if err := cacheCleanCmd(); err != nil { 42 os.Exit(2) 43 } 44 }, 45 46 Use: docs.CacheCleanUse, 47 Short: docs.CacheCleanShort, 48 Long: docs.CacheCleanLong, 49 Example: docs.CacheCleanExample, 50 } 51 52 func cacheCleanCmd() error { 53 err := singularity.CleanSingularityCache(cleanAll, cacheCleanTypes, cacheName) 54 if err != nil { 55 sylog.Fatalf("Failed while clean cache: %v", err) 56 os.Exit(255) 57 } 58 59 return err 60 }