This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/lithammer/dedent" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/weaveworks/ignite/cmd/ignite/run" | ||
"github.com/weaveworks/ignite/pkg/errutils" | ||
) | ||
|
||
// NewCmdInspect inspects an Ignite Object | ||
func NewCmdInspect(out io.Writer) *cobra.Command { | ||
i := &run.InspectFlags{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "inspect <kind> <object>", | ||
Short: "Inspect an Ignite Object", | ||
Long: dedent.Dedent(` | ||
Retrieve information about the given object of the given kind. | ||
The kind can be "image", "kernel" or "vm". The object is matched | ||
by prefix based on its ID and name. Outputs JSON by default, can | ||
be overridden with the output flag (-o, --output). | ||
`), | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
errutils.Check(func() error { | ||
io, err := i.NewInspectOptions(args[0], args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return run.Inspect(io) | ||
}()) | ||
}, | ||
} | ||
|
||
addInspectFlags(cmd.Flags(), i) | ||
return cmd | ||
} | ||
|
||
func addInspectFlags(fs *pflag.FlagSet, i *run.InspectFlags) { | ||
fs.StringVarP(&i.OutputFormat, "output", "o", "json", "Output the object in the specified format") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package run | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme" | ||
"github.com/weaveworks/ignite/pkg/client" | ||
"github.com/weaveworks/ignite/pkg/filter" | ||
|
||
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1" | ||
) | ||
|
||
type InspectFlags struct { | ||
OutputFormat string | ||
} | ||
|
||
type inspectOptions struct { | ||
*InspectFlags | ||
object meta.Object | ||
} | ||
|
||
func (i *InspectFlags) NewInspectOptions(k, objectMatch string) (*inspectOptions, error) { | ||
var err error | ||
var kind meta.Kind | ||
io := &inspectOptions{InspectFlags: i} | ||
|
||
switch strings.ToLower(k) { | ||
case meta.KindImage.Lower(): | ||
kind = meta.KindImage | ||
case meta.KindKernel.Lower(): | ||
kind = meta.KindKernel | ||
case meta.KindVM.Lower(): | ||
kind = meta.KindVM | ||
default: | ||
return nil, fmt.Errorf("unrecognized kind: %q", k) | ||
} | ||
|
||
if io.object, err = client.Dynamic(kind).Find(filter.NewIDNameFilter(objectMatch)); err != nil { | ||
return nil, err | ||
} | ||
|
||
return io, nil | ||
} | ||
|
||
func Inspect(io *inspectOptions) error { | ||
var b []byte | ||
var err error | ||
|
||
// Select the encoder and encode the object with it | ||
switch io.OutputFormat { | ||
case "json": | ||
b, err = scheme.Serializer.EncodeJSON(io.object) | ||
case "yaml": | ||
b, err = scheme.Serializer.EncodeYAML(io.object) | ||
default: | ||
err = fmt.Errorf("unrecognized output format: %q", io.OutputFormat) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Print the encoded object | ||
fmt.Println(string(bytes.TrimSpace(b))) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## ignite inspect | ||
|
||
Inspect an Ignite Object | ||
|
||
### Synopsis | ||
|
||
|
||
Retrieve information about the given object of the given kind. | ||
The kind can be "image", "kernel" or "vm". The object is matched | ||
by prefix based on its ID and name. Outputs JSON by default, can | ||
be overridden to YAML with the yaml flag (-y, --yaml). | ||
|
||
|
||
``` | ||
ignite inspect <kind> <object> [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for inspect | ||
-o, --output string Output the object in the specified format (default "json") | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ignite](ignite.md) - ignite: easily run Firecracker VMs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: grouping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c6622cf.