This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors show command into standalone struct (#631)
- this common struct can then be shared between the `duffle show` and `duffle bundle show` commands
- Loading branch information
1 parent
dfb8ec8
commit fa76d3e
Showing
3 changed files
with
89 additions
and
41 deletions.
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,81 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newBundleShowCmd(w io.Writer) *cobra.Command { | ||
bsc := &bundleShowCmd{} | ||
bsc.w = w | ||
|
||
cmd := &cobra.Command{ | ||
Use: "show NAME", | ||
Short: "return low-level information on application bundles", | ||
Long: bsc.usage(true), | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
bsc.name = args[0] | ||
|
||
return bsc.run() | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.BoolVarP(&bsc.insecure, "insecure", "k", false, "Do not verify the bundle (INSECURE)") | ||
flags.BoolVarP(&bsc.raw, "raw", "r", false, "Display the raw bundle manifest") | ||
|
||
return cmd | ||
} | ||
|
||
type bundleShowCmd struct { | ||
name string | ||
insecure bool | ||
raw bool | ||
w io.Writer | ||
} | ||
|
||
func (bsc *bundleShowCmd) usage(bundleSubCommand bool) string { | ||
commandName := "show" | ||
if bundleSubCommand { | ||
commandName = "bundle show" | ||
} | ||
|
||
return fmt.Sprintf(` Returns information about an application bundle. | ||
Example: | ||
$ duffle %s duffle/example:0.1.0 | ||
To display unsigned bundles, pass the --insecure flag: | ||
$ duffle %s duffle/unsinged-example:0.1.0 --insecure | ||
`, commandName, commandName) | ||
} | ||
|
||
func (bsc *bundleShowCmd) run() error { | ||
bundleFile, err := getBundleFilepath(bsc.name, homePath(), bsc.insecure) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if bsc.raw { | ||
f, err := os.Open(bundleFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = io.Copy(bsc.w, f) | ||
return err | ||
} | ||
|
||
bun, err := loadBundle(bundleFile, bsc.insecure) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = bun.WriteTo(bsc.w) | ||
|
||
return err | ||
} |
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