mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +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")
|
||||
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
|
||||
log.SetFormatter(new(infoFormatter))
|
||||
log.SetLevel(log.InfoLevel)
|
||||
@ -85,8 +68,7 @@ func main() {
|
||||
case "build":
|
||||
build(args[1:])
|
||||
case "run":
|
||||
runCmd.Parse(args[1:])
|
||||
run(*runCPUs, *runMem, *runDiskSz, *runDisk, runCmd.Args())
|
||||
run(args[1:])
|
||||
case "help":
|
||||
flag.Usage()
|
||||
default:
|
||||
|
@ -3,20 +3,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"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"
|
||||
if len(args) > 0 {
|
||||
prefix = args[0]
|
||||
if len(remArgs) > 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")
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func run(cpus, mem, diskSz int, userData string, args []string) {
|
||||
func run(args []string) {
|
||||
log.Fatalf("'run' is not supported yet on your OS")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user