diff --git a/src/cmd/moby/run.go b/src/cmd/moby/run.go new file mode 100644 index 000000000..1b91c8af2 --- /dev/null +++ b/src/cmd/moby/run.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + "runtime" + + log "github.com/Sirupsen/logrus" +) + +func runUsage() { + fmt.Printf("USAGE: %s run [backend] [options] [prefix]\n\n", os.Args[0]) + + fmt.Printf("'backend' specifies the run backend.\n") + fmt.Printf("If not specified the platform specific default will be used\n") + fmt.Printf("Supported backends are (default platform in brackets):\n") + fmt.Printf(" hyperkit [macOS]\n") + fmt.Printf("\n") + fmt.Printf("'options' are the backend specific options.\n") + fmt.Printf("See 'moby run [backend] --help' for details.\n\n") + fmt.Printf("'prefix' specifies the path to the VM image.\n") + fmt.Printf("It defaults to './moby'.\n") +} + +func run(args []string) { + if len(args) < 1 { + runUsage() + os.Exit(1) + } + + switch args[0] { + case "help", "-h", "-help", "--help": + runUsage() + os.Exit(0) + case "hyperkit": + runHyperKit(args[1:]) + default: + switch runtime.GOOS { + case "darwin": + runHyperKit(args) + default: + log.Errorf("There currently is no default 'run' backend for your platform.") + } + } +} diff --git a/src/cmd/moby/run_fallback.go b/src/cmd/moby/run_fallback.go deleted file mode 100644 index d15f6922a..000000000 --- a/src/cmd/moby/run_fallback.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !darwin - -package main - -import ( - log "github.com/Sirupsen/logrus" -) - -func run(args []string) { - log.Fatalf("'run' is not supported yet on your OS") -} diff --git a/src/cmd/moby/run_darwin.go b/src/cmd/moby/run_hyperkit.go similarity index 57% rename from src/cmd/moby/run_darwin.go rename to src/cmd/moby/run_hyperkit.go index 9b4ac486e..d29267cb0 100644 --- a/src/cmd/moby/run_darwin.go +++ b/src/cmd/moby/run_hyperkit.go @@ -1,5 +1,3 @@ -// +build darwin - package main import ( @@ -13,33 +11,33 @@ import ( ) // Process the run arguments and execute run -func run(args []string) { - runCmd := flag.NewFlagSet("run", flag.ExitOnError) - runCmd.Usage = func() { - fmt.Printf("USAGE: %s run [options] [prefix]\n\n", os.Args[0]) +func runHyperKit(args []string) { + hyperkitCmd := flag.NewFlagSet("hyperkit", flag.ExitOnError) + hyperkitCmd.Usage = func() { + fmt.Printf("USAGE: %s run hyperkit [options] [prefix]\n\n", os.Args[0]) fmt.Printf("'prefix' specifies the path to the VM image.\n") fmt.Printf("It defaults to './moby'.\n") fmt.Printf("\n") fmt.Printf("Options:\n") - runCmd.PrintDefaults() + hyperkitCmd.PrintDefaults() } - runCPUs := runCmd.Int("cpus", 1, "Number of CPUs") - runMem := runCmd.Int("mem", 1024, "Amount of memory in MB") - runDiskSz := runCmd.Int("disk-size", 0, "Size of Disk in MB") - runDisk := runCmd.String("disk", "", "Path to disk image to used") + runCPUs := hyperkitCmd.Int("cpus", 1, "Number of CPUs") + runMem := hyperkitCmd.Int("mem", 1024, "Amount of memory in MB") + runDiskSz := hyperkitCmd.Int("disk-size", 0, "Size of Disk in MB") + runDisk := hyperkitCmd.String("disk", "", "Path to disk image to used") - runCmd.Parse(args) - remArgs := runCmd.Args() + hyperkitCmd.Parse(args) + remArgs := hyperkitCmd.Args() prefix := "moby" if len(remArgs) > 0 { prefix = remArgs[0] } - runInternal(*runCPUs, *runMem, *runDiskSz, *runDisk, prefix) + runHyperKitInternal(*runCPUs, *runMem, *runDiskSz, *runDisk, prefix) } -func runInternal(cpus, mem, diskSz int, disk, prefix string) { +func runHyperKitInternal(cpus, mem, diskSz int, disk, prefix string) { cmdline, err := ioutil.ReadFile(prefix + "-cmdline") if err != nil { log.Fatalf("Cannot open cmdline file: %v", err)