github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podmanV2/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"reflect"
     6  
     7  	_ "github.com/containers/libpod/cmd/podmanV2/containers"
     8  	_ "github.com/containers/libpod/cmd/podmanV2/healthcheck"
     9  	_ "github.com/containers/libpod/cmd/podmanV2/images"
    10  	_ "github.com/containers/libpod/cmd/podmanV2/networks"
    11  	_ "github.com/containers/libpod/cmd/podmanV2/pods"
    12  	"github.com/containers/libpod/cmd/podmanV2/registry"
    13  	_ "github.com/containers/libpod/cmd/podmanV2/system"
    14  	_ "github.com/containers/libpod/cmd/podmanV2/volumes"
    15  	"github.com/containers/storage/pkg/reexec"
    16  )
    17  
    18  func init() {
    19  	// This is the bootstrap configuration, if user gives
    20  	// CLI flags parts of this configuration may be overwritten
    21  	registry.PodmanOptions = registry.NewPodmanConfig()
    22  }
    23  
    24  func main() {
    25  	if reexec.Init() {
    26  		// We were invoked with a different argv[0] indicating that we
    27  		// had a specific job to do as a subprocess, and it's done.
    28  		return
    29  	}
    30  	for _, c := range registry.Commands {
    31  		if Contains(registry.PodmanOptions.EngineMode, c.Mode) {
    32  			parent := rootCmd
    33  			if c.Parent != nil {
    34  				parent = c.Parent
    35  			}
    36  			parent.AddCommand(c.Command)
    37  		}
    38  	}
    39  
    40  	Execute()
    41  	os.Exit(0)
    42  }
    43  
    44  func Contains(item interface{}, slice interface{}) bool {
    45  	s := reflect.ValueOf(slice)
    46  
    47  	switch s.Kind() {
    48  	case reflect.Array:
    49  		fallthrough
    50  	case reflect.Slice:
    51  		break
    52  	default:
    53  		return false
    54  	}
    55  
    56  	for i := 0; i < s.Len(); i++ {
    57  		if s.Index(i).Interface() == item {
    58  			return true
    59  		}
    60  	}
    61  	return false
    62  }