-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.go
41 lines (31 loc) · 1009 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"fmt"
"os"
)
func cliUsage() {
fmt.Println("Usage: sudo ./go-container [OPTIONS] <image name> <command>")
flag.PrintDefaults()
}
func parseCliArgs() (container, networkConfig) {
c := container{}
net := networkConfig{}
flag.Usage = cliUsage
// Container.
flag.StringVar(&c.containersDir, "c", "containers", "directory to store containers")
flag.StringVar(&c.imagesDir, "i", "images", "directory to find container images")
flag.IntVar(&c.cpuShares, "cpu", 0, "cpu shares (relative weight)")
flag.StringVar(&c.memLimit, "mem", "", "memory limit in bytes; suffixes can be used")
// NetworkConfig.
flag.StringVar(&net.bridgeAddr, "bridge-addr", "10.10.10.1/24", "CIDR bridge address; replaces current if present")
flag.StringVar(&net.containerVethAddr, "container-addr", "10.10.10.2/24", "CIDR container veth address")
flag.Parse()
if flag.NArg() < 2 {
flag.Usage()
os.Exit(1)
}
c.imageName = flag.Arg(0)
c.command = flag.Args()[1:]
return c, net
}