Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 48f17c0

Browse files
author
Matthieu Nottale
committed
inspect: Dump metadatas.
Signed-off-by: Matthieu Nottale <[email protected]>
1 parent 3727683 commit 48f17c0

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

cmd/inspect.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56

7+
"github.com/docker/lunchbox/packager"
68
"github.com/spf13/cobra"
79
)
810

911
// inspectCmd represents the inspect command
1012
var inspectCmd = &cobra.Command{
1113
Use: "inspect <app-name>",
1214
Short: "Retrieve metadata for a given app package",
15+
Args: cobra.ExactArgs(1),
1316
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println("inspect called")
17+
err := packager.Inspect(args[0])
18+
if err != nil {
19+
fmt.Printf("%v\n", err)
20+
os.Exit(1)
21+
}
1522
},
1623
}
1724

1825
func init() {
1926
rootCmd.AddCommand(inspectCmd)
20-
21-
// Here you will define your flags and configuration settings.
22-
23-
// Cobra supports Persistent Flags which will work for this command
24-
// and all subcommands, e.g.:
25-
// inspectCmd.PersistentFlags().String("foo", "", "A help for foo")
26-
27-
// Cobra supports local flags which will only run when this command
28-
// is called directly, e.g.:
29-
// inspectCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
3027
}

packager/inspect.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package packager
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"path"
7+
8+
"github.com/docker/lunchbox/types"
9+
yaml "gopkg.in/yaml.v2"
10+
)
11+
12+
// Inspect dumps the metadata of an app
13+
func Inspect(appname string) error {
14+
appname, cleanup, err := Extract(appname)
15+
if err != nil {
16+
return err
17+
}
18+
defer cleanup()
19+
metaFile := path.Join(appname, "metadata.yml")
20+
metaContent, err := ioutil.ReadFile(metaFile)
21+
if err != nil {
22+
return err
23+
}
24+
var meta types.AppMetadata
25+
err = yaml.Unmarshal(metaContent, &meta)
26+
if err != nil {
27+
return err
28+
}
29+
smeta, err := yaml.Marshal(meta)
30+
if err != nil {
31+
return err
32+
}
33+
fmt.Println(string(smeta))
34+
return nil
35+
}

0 commit comments

Comments
 (0)