mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
cli: Move "run" flag processing into the run implmentation
While at it also fix up the HyperKit run help message. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
bc5e4c8a14
commit
13e3d88bdd
@ -40,23 +40,6 @@ func main() {
|
|||||||
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
||||||
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
||||||
|
|
||||||
runCmd := flag.NewFlagSet("run", flag.ExitOnError)
|
|
||||||
runCmd.Usage = func() {
|
|
||||||
fmt.Printf("USAGE: %s run [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()
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Printf("If 'data' is supplied or if 'background' is selected\n")
|
|
||||||
fmt.Printf("some per VM state is kept in a sub-directory in the ~/.moby\n")
|
|
||||||
}
|
|
||||||
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")
|
|
||||||
|
|
||||||
// Set up logging
|
// Set up logging
|
||||||
log.SetFormatter(new(infoFormatter))
|
log.SetFormatter(new(infoFormatter))
|
||||||
log.SetLevel(log.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
@ -85,8 +68,7 @@ func main() {
|
|||||||
case "build":
|
case "build":
|
||||||
build(args[1:])
|
build(args[1:])
|
||||||
case "run":
|
case "run":
|
||||||
runCmd.Parse(args[1:])
|
run(args[1:])
|
||||||
run(*runCPUs, *runMem, *runDiskSz, *runDisk, runCmd.Args())
|
|
||||||
case "help":
|
case "help":
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
default:
|
default:
|
||||||
|
@ -3,20 +3,43 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/hyperkit/go"
|
"github.com/docker/hyperkit/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(cpus, mem, diskSz int, disk string, args []string) {
|
// 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])
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
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")
|
||||||
|
|
||||||
|
runCmd.Parse(args)
|
||||||
|
remArgs := runCmd.Args()
|
||||||
|
|
||||||
prefix := "moby"
|
prefix := "moby"
|
||||||
if len(args) > 0 {
|
if len(remArgs) > 0 {
|
||||||
prefix = args[0]
|
prefix = remArgs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runInternal(*runCPUs, *runMem, *runDiskSz, *runDisk, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runInternal(cpus, mem, diskSz int, disk, prefix string) {
|
||||||
cmdline, err := ioutil.ReadFile(prefix + "-cmdline")
|
cmdline, err := ioutil.ReadFile(prefix + "-cmdline")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot open cmdline file: %v", err)
|
log.Fatalf("Cannot open cmdline file: %v", err)
|
||||||
@ -42,10 +65,3 @@ func run(cpus, mem, diskSz int, disk string, args []string) {
|
|||||||
log.Fatalf("Cannot run hyperkit: %v", err)
|
log.Fatalf("Cannot run hyperkit: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHome() string {
|
|
||||||
if usr, err := user.Current(); err == nil {
|
|
||||||
return usr.HomeDir
|
|
||||||
}
|
|
||||||
return os.Getenv("HOME")
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,6 @@ import (
|
|||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(cpus, mem, diskSz int, userData string, args []string) {
|
func run(args []string) {
|
||||||
log.Fatalf("'run' is not supported yet on your OS")
|
log.Fatalf("'run' is not supported yet on your OS")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user