57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
"forge.cadoles.com/arcad/edge/pkg/bundle"
|
|
"github.com/pkg/errors"
|
|
"github.com/urfave/cli/v2"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
func InfoCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "info",
|
|
Usage: "Print app manifest informations",
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "path",
|
|
Usage: "use `PATH` as app bundle (zip, zim or directory bundle)",
|
|
Aliases: []string{"p"},
|
|
Value: "",
|
|
Required: true,
|
|
},
|
|
},
|
|
Action: func(ctx *cli.Context) error {
|
|
appPath := ctx.String("path")
|
|
|
|
bundle, err := bundle.FromPath(appPath)
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not load app bundle")
|
|
}
|
|
|
|
manifest, err := app.LoadManifest(bundle)
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not load app manifest")
|
|
}
|
|
|
|
if valid, err := manifest.Validate(manifestMetadataValidators...); !valid {
|
|
return errors.Wrap(err, "invalid app manifest")
|
|
}
|
|
|
|
encoder := yaml.NewEncoder(os.Stdout)
|
|
|
|
if err := encoder.Encode(manifest); err != nil {
|
|
return errors.Wrap(err, "could not encode manifest")
|
|
}
|
|
|
|
if err := encoder.Close(); err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|