Skip to content

Commit

Permalink
support multiple inspection
Browse files Browse the repository at this point in the history
Signed-off-by: 程飞 <[email protected]>
  • Loading branch information
faycheng committed Mar 28, 2018
1 parent 2f15bb9 commit 469a01e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cli/image_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (i *ImageInspectCommand) Init(c *Cli) {
Use: "inspect [OPTIONS] IMAGE",
Short: "Display detailed information on one image",
Long: imageInspectDescription,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return i.runInspect(args)
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
inspect.MultiInspect(args, i.runInspect)
},
Example: i.example(),
}
Expand Down
6 changes: 3 additions & 3 deletions cli/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (p *InspectCommand) Init(c *Cli) {
Use: "inspect [OPTIONS] CONTAINER",
Short: "Get the detailed information of container",
Long: inspectDescription,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return p.runInspect(args)
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
inspect.MultiInspect(args, p.runInspect)
},
Example: inspectExample(),
}
Expand Down
14 changes: 14 additions & 0 deletions cli/inspect/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/alibaba/pouch/pkg/utils/templates"

"fmt"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -75,6 +76,19 @@ func Inspect(out io.Writer, ref string, tmplStr string, getRef GetRefFunc) error
return nil
}

// RunInspectFunc is a function which used by MultiInspect
type RunInspectFunc func(args []string) error

// MultiInspect Apply function to every item of ref.
func MultiInspect(refs []string, inspect RunInspectFunc) {
for _, ref := range refs {
err := inspect([]string{ref})
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
}
}
}

// Inspect executes the inspect template.
func (i *TemplateInspector) Inspect(typedElement interface{}) error {
buf := new(bytes.Buffer)
Expand Down
6 changes: 3 additions & 3 deletions cli/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ func (n *NetworkInspectCommand) Init(c *Cli) {
Use: "inspect [OPTIONS] NAME",
Short: "Inspect a pouch network",
Long: networkInspectDescription,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return n.runNetworkInspect(args)
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
inspect.MultiInspect(args, n.runNetworkInspect)
},
Example: networkInspectExample(),
}
Expand Down
6 changes: 3 additions & 3 deletions cli/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ func (v *VolumeInspectCommand) Init(c *Cli) {
Use: "inspect [OPTIONS] NAME",
Short: "Inspect a pouch volume",
Long: volumeInspectDescription,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return v.runVolumeInspect(args)
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
inspect.MultiInspect(args, v.runVolumeInspect)
},
Example: volumeInspectExample(),
}
Expand Down

0 comments on commit 469a01e

Please sign in to comment.