Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple ids. #255

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 45 additions & 40 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,31 @@ var createContainerCommand = cli.Command{

var startContainerCommand = cli.Command{
Name: "start",
Usage: "Start a created container",
ArgsUsage: "CONTAINER",
Usage: "Start one or more created containers",
ArgsUsage: "CONTAINER [CONTAINER...]",
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getRuntimeClient(context); err != nil {
return err
}

err := StartContainer(runtimeClient, containerID)
if err != nil {
return fmt.Errorf("Starting the container failed: %v", err)
for i := 0; i < context.NArg(); i++ {
containerID := context.Args().Get(i)
err := StartContainer(runtimeClient, containerID)
if err != nil {
return fmt.Errorf("Starting the container %q failed: %v", containerID, err)
}
}
return nil
},
}

var updateContainerCommand = cli.Command{
Name: "update",
Usage: "Update a running container",
ArgsUsage: "CONTAINER",
Usage: "Update one or more running containers",
ArgsUsage: "CONTAINER [CONTAINER...]",
Flags: []cli.Flag{
cli.Int64Flag{
Name: "cpu-period",
Expand Down Expand Up @@ -135,11 +136,9 @@ var updateContainerCommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getRuntimeClient(context); err != nil {
return err
}
Expand All @@ -154,18 +153,21 @@ var updateContainerCommand = cli.Command{
OomScoreAdj: context.Int64("oom-score-adj"),
}

err := UpdateContainerResources(runtimeClient, containerID, options)
if err != nil {
return fmt.Errorf("Updating container resources failed: %v", err)
for i := 0; i < context.NArg(); i++ {
containerID := context.Args().Get(i)
err := UpdateContainerResources(runtimeClient, containerID, options)
if err != nil {
return fmt.Errorf("Updating container resources for %q failed: %v", containerID, err)
}
}
return nil
},
}

var stopContainerCommand = cli.Command{
Name: "stop",
Usage: "Stop a running container",
ArgsUsage: "CONTAINER",
Usage: "Stop one or more running containers",
ArgsUsage: "CONTAINER [CONTAINER...]",
Flags: []cli.Flag{
cli.Int64Flag{
Name: "timeout, t",
Expand All @@ -174,49 +176,51 @@ var stopContainerCommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getRuntimeClient(context); err != nil {
return err
}

err := StopContainer(runtimeClient, containerID, context.Int64("timeout"))
if err != nil {
return fmt.Errorf("Stopping the container failed: %v", err)
for i := 0; i < context.NArg(); i++ {
containerID := context.Args().Get(i)
err := StopContainer(runtimeClient, containerID, context.Int64("timeout"))
if err != nil {
return fmt.Errorf("Stopping the container %q failed: %v", containerID, err)
}
}
return nil
},
}

var removeContainerCommand = cli.Command{
Name: "rm",
Usage: "Remove a container",
ArgsUsage: "CONTAINER",
Usage: "Remove one or more containers",
ArgsUsage: "CONTAINER [CONTAINER...]",
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getRuntimeClient(context); err != nil {
return err
}

err := RemoveContainer(runtimeClient, containerID)
if err != nil {
return fmt.Errorf("Removing the container failed: %v", err)
for i := 0; i < context.NArg(); i++ {
containerID := context.Args().Get(i)
err := RemoveContainer(runtimeClient, containerID)
if err != nil {
return fmt.Errorf("Removing the container %q failed: %v", containerID, err)
}
}
return nil
},
}

var containerStatusCommand = cli.Command{
Name: "inspect",
Usage: "Display the status of a container",
ArgsUsage: "CONTAINER",
Usage: "Display the status of one or more containers",
ArgsUsage: "CONTAINER [CONTAINER...]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Expand All @@ -228,18 +232,19 @@ var containerStatusCommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getRuntimeClient(context); err != nil {
return err
}

err := ContainerStatus(runtimeClient, containerID, context.String("output"), context.Bool("quiet"))
if err != nil {
return fmt.Errorf("Getting the status of the container failed: %v", err)
for i := 0; i < context.NArg(); i++ {
containerID := context.Args().Get(i)
err := ContainerStatus(runtimeClient, containerID, context.String("output"), context.Bool("quiet"))
if err != nil {
return fmt.Errorf("Getting the status of the container %q failed: %v", containerID, err)
}
}
return nil
},
Expand Down
118 changes: 61 additions & 57 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ var listImageCommand = cli.Command{

var imageStatusCommand = cli.Command{
Name: "inspecti",
Usage: "Return the status of an image",
ArgsUsage: "IMAGEID",
Usage: "Return the status of one ore more images",
ArgsUsage: "IMAGEID [IMAGEID...]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Expand All @@ -200,54 +200,57 @@ var imageStatusCommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
id := context.Args().First()
if id == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getImageClient(context); err != nil {
return err
}

verbose := !(context.Bool("quiet"))
r, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status request failed: %v", err)
}
image := r.Image
if image == nil {
return fmt.Errorf("no such image present")
}

output := context.String("output")
if output == "" { // default to json output
output = "json"
}
for i := 0; i < context.NArg(); i++ {
id := context.Args().Get(i)

status, err := protobufObjectToJSON(r.Image)
if err != nil {
return err
}
switch output {
case "json", "yaml":
return outputStatusInfo(status, r.Info, output)
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}
r, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status for %q request failed: %v", id, err)
}
image := r.Image
if image == nil {
return fmt.Errorf("no such image %q present", id)
}

// otherwise output in table format
fmt.Printf("ID: %s\n", image.Id)
for _, tag := range image.RepoTags {
fmt.Printf("Tag: %s\n", tag)
}
for _, digest := range image.RepoDigests {
fmt.Printf("Digest: %s\n", digest)
}
size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3)
fmt.Printf("Size: %s\n", size)
if verbose {
fmt.Printf("Info: %v\n", r.GetInfo())
status, err := protobufObjectToJSON(r.Image)
if err != nil {
return fmt.Errorf("failed to marshal status to json for %q: %v", id, err)
}
switch output {
case "json", "yaml":
if err := outputStatusInfo(status, r.Info, output); err != nil {
return fmt.Errorf("failed to output status for %q: %v", id, err)
}
continue
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}

// otherwise output in table format
fmt.Printf("ID: %s\n", image.Id)
for _, tag := range image.RepoTags {
fmt.Printf("Tag: %s\n", tag)
}
for _, digest := range image.RepoDigests {
fmt.Printf("Digest: %s\n", digest)
}
size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3)
fmt.Printf("Size: %s\n", size)
if verbose {
fmt.Printf("Info: %v\n", r.GetInfo())
}
}

return nil
Expand All @@ -256,33 +259,34 @@ var imageStatusCommand = cli.Command{

var removeImageCommand = cli.Command{
Name: "rmi",
Usage: "Remove an image",
ArgsUsage: "IMAGEID",
Usage: "Remove one or more images",
ArgsUsage: "IMAGEID [IMAGEID...]",
Action: func(context *cli.Context) error {
id := context.Args().First()
if id == "" {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
}

if err := getImageClient(context); err != nil {
return err
}
for i := 0; i < context.NArg(); i++ {
id := context.Args().Get(i)

var verbose = false
status, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status request failed: %v", err)
}
if status.Image == nil {
return fmt.Errorf("no such image %s", id)
}
var verbose = false
status, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status request for %q failed: %v", id, err)
}
if status.Image == nil {
return fmt.Errorf("no such image %s", id)
}

_, err = RemoveImage(imageClient, id)
if err != nil {
return fmt.Errorf("error of removing image %q: %v", id, err)
}
for _, repoTag := range status.Image.RepoTags {
fmt.Printf("Deleted: %s\n", repoTag)
_, err = RemoveImage(imageClient, id)
if err != nil {
return fmt.Errorf("error of removing image %q: %v", id, err)
}
for _, repoTag := range status.Image.RepoTags {
fmt.Printf("Deleted: %s\n", repoTag)
}
}
return nil
},
Expand Down
Loading