diff --git a/clab/clab.go b/clab/clab.go index 764648e26..8112dfaac 100644 --- a/clab/clab.go +++ b/clab/clab.go @@ -7,6 +7,7 @@ package clab import ( "context" "fmt" + "os" "path" "strings" "sync" @@ -58,6 +59,12 @@ func WithTimeout(dur time.Duration) ClabOption { func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool) ClabOption { return func(c *CLab) { + if name == "" { + name = os.Getenv("CLAB_RUNTIME") + if name == "" { + name = runtime.DockerRuntime + } + } if rInit, ok := runtime.ContainerRuntimes[name]; ok { c.Runtime = rInit() err := c.Runtime.Init( diff --git a/cmd/root.go b/cmd/root.go index f5ade243e..6772500b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,7 +11,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/srl-labs/containerlab/runtime" ) var debug bool @@ -52,8 +51,7 @@ func init() { _ = rootCmd.MarkPersistentFlagFilename("topo", "*.yaml", "*.yml") rootCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "lab name") rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "", 30*time.Second, "timeout for docker requests, e.g: 30s, 1m, 2m30s") - rootCmd.PersistentFlags().StringVarP(&rt, "runtime", "r", runtime.DockerRuntime, "container runtime") - + rootCmd.PersistentFlags().StringVarP(&rt, "runtime", "r", "", "container runtime") } // returns an error if topo path is not provided