diff --git a/cmd/cli/command/app/info.go b/cmd/cli/command/app/info.go new file mode 100644 index 0000000..482c974 --- /dev/null +++ b/cmd/cli/command/app/info.go @@ -0,0 +1,56 @@ +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 + }, + } +} diff --git a/cmd/cli/command/app/root.go b/cmd/cli/command/app/root.go index 31fe484..d2773c2 100644 --- a/cmd/cli/command/app/root.go +++ b/cmd/cli/command/app/root.go @@ -12,6 +12,7 @@ func Root() *cli.Command { RunCommand(), PackageCommand(), HashPasswordCommand(), + InfoCommand(), }, } }