Skip to content

Commit

Permalink
move argumet container id to subcommand and update ArgsUsage
Browse files Browse the repository at this point in the history
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
  • Loading branch information
laijs committed Apr 13, 2016
1 parent 59986ca commit 8976e66
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
13 changes: 11 additions & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ import (
var execCommand = cli.Command{
Name: "exec",
Usage: "exec a new program in runv container",
ArgsUsage: `<container-id> <container command>
Where "<container-id>" is the name for the instance of the container and
"<container command>" is the command to be executed in the container.
For example, if the container is configured to run the linux ps command the
following will output a list of processes running in the container:
# runv exec <container-id> ps`,
Action: func(context *cli.Context) {
root := context.GlobalString("root")
container := context.GlobalString("id")
config, err := loadProcessConfig(context.Args().First())
container := context.Args().First()
config, err := loadProcessConfig(context.Args().Get(1))
if err != nil {
fmt.Printf("load process config failed %v\n", err)
os.Exit(-1)
Expand Down
13 changes: 11 additions & 2 deletions kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ type killContainerCmd struct {
var killCommand = cli.Command{
Name: "kill",
Usage: "kill sends the specified signal (default: SIGTERM) to the container's init process",
ArgsUsage: `<container-id> <signal>
Where "<container-id>" is the name for the instance of the container and
"<signal>" is the signal to be sent to the init process.
For example, if the container id is "ubuntu01" the following will send a "KILL"
signal to the init process of the "ubuntu01" container:
# runv kill ubuntu01 KILL`,
Action: func(context *cli.Context) {
root := context.GlobalString("root")
container := context.GlobalString("id")
sigstr := context.Args().First()
container := context.Args().First()
sigstr := context.Args().Get(1)
if sigstr == "" {
sigstr = "SIGTERM"
}
Expand Down
18 changes: 2 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/codegangsta/cli"
Expand Down Expand Up @@ -34,10 +33,10 @@ After creating a spec for your root filesystem, you can execute a container
in your shell by running:
# cd /mycontainer
# runv start start [ -b bundle ]
# runv start start [ -b bundle ] <container-id>
If not specified, the default value for the 'bundle' is the current directory.
'Bundle' is the directory where '` + specConfig + `' and '` + runtimeConfig + `' must be located.`
'Bundle' is the directory where '` + specConfig + `' must be located.`
)

func main() {
Expand All @@ -51,11 +50,6 @@ func main() {
app.Usage = usage
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "id",
Value: getDefaultID(),
Usage: "specify the ID to be used for the container",
},
cli.StringFlag{
Name: "root",
Value: "/run/runv",
Expand Down Expand Up @@ -90,14 +84,6 @@ func main() {
}
}

func getDefaultID() string {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
return filepath.Base(cwd)
}

func getDefaultDriver() string {
if runtime.GOOS == "linux" {
return "qemu"
Expand Down
15 changes: 14 additions & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type startConfig struct {

func loadStartConfig(context *cli.Context) (*startConfig, error) {
config := &startConfig{
Name: context.GlobalString("id"),
Name: context.Args().First(),
Root: context.GlobalString("root"),
Driver: context.GlobalString("driver"),
Kernel: context.GlobalString("kernel"),
Expand Down Expand Up @@ -80,6 +80,19 @@ func firstExistingFile(candidates []string) string {
var startCommand = cli.Command{
Name: "start",
Usage: "create and run a container",
ArgsUsage: `<container-id>
Where "<container-id>" is your name for the instance of the container that you
are starting. The name you provide for the container instance must be unique on
your host.`,
Description: `The start command creates an instance of a container for a bundle. The bundle
is a directory with a specification file named "` + specConfig + `" and a root
filesystem.
The specification file includes an args parameter. The args parameter is used
to specify command(s) that get run when the container is started. To change the
command(s) that get executed on start, edit the args parameter of the spec. See
"runv spec --help" for more explanation.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bundle, b",
Expand Down

0 comments on commit 8976e66

Please sign in to comment.