github.com/operator-framework/operator-lifecycle-manager@v0.30.0/cmd/copy-content/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/otiai10/copy"
     9  )
    10  
    11  func main() {
    12  	catalogSource := flag.String("catalog.from", "", "Path to catalog contents to copy.")
    13  	catalogDestination := flag.String("catalog.to", "", "Path to where catalog contents should be copied.")
    14  	cacheSource := flag.String("cache.from", "", "Path to cache contents to copy.")
    15  	cacheDestination := flag.String("cache.to", "", "Path to where cache contents should be copied.")
    16  	flag.Parse()
    17  
    18  	for flagName, value := range map[string]*string{
    19  		"catalog.from": catalogSource,
    20  		"catalog.to":   catalogDestination,
    21  		"cache.from":   cacheSource,
    22  		"cache.to":     cacheDestination,
    23  	} {
    24  		if value == nil || *value == "" {
    25  			fmt.Printf("--%s is required", flagName)
    26  			os.Exit(1)
    27  		}
    28  	}
    29  
    30  	for from, to := range map[string]string{
    31  		*catalogSource: *catalogDestination,
    32  		*cacheSource:   *cacheDestination,
    33  	} {
    34  		if err := os.RemoveAll(to); err != nil {
    35  			fmt.Printf("failed to remove %s: %s", to, err)
    36  			os.Exit(1)
    37  		}
    38  		if err := copy.Copy(from, to); err != nil {
    39  			fmt.Printf("failed to copy %s to %s: %s\n", from, to, err)
    40  			os.Exit(1)
    41  		}
    42  	}
    43  }