-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
executable file
·43 lines (41 loc) · 1.13 KB
/
create.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
42
43
package command
import (
"github.com/songxinjianqwe/capsule/cli/util"
"github.com/songxinjianqwe/capsule/libcapsule/facade"
"github.com/urfave/cli"
)
var CreateCommand = cli.Command{
Name: "create",
Usage: "create a container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "bundle, b",
Value: "",
Usage: `path to the root of the bundle directory, defaults to the current directory`,
},
cli.StringFlag{
Name: "network, net",
Usage: `network connected by container`,
},
cli.StringSliceFlag{
Name: "port, p",
Usage: `port mappings, example: host port:container port`,
},
},
Action: func(ctx *cli.Context) error {
if err := util.CheckArgs(ctx, 1, util.ExactArgs); err != nil {
return err
}
// 将spec转为container config对象
// 加载factory
// 调用factory.create
spec, err := facade.LoadSpec(ctx.String("bundle"))
if err != nil {
return err
}
if err := facade.CreateOrRunContainer(ctx.GlobalString("root"), ctx.Args().First(), ctx.String("bundle"), spec, facade.ContainerActCreate, false, ctx.String("network"), ctx.StringSlice("port")); err != nil {
return err
}
return nil
},
}