Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pack extension --help #1603

Merged
merged 5 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
rootCmd.AddCommand(commands.Build(logger, cfg, packClient))
rootCmd.AddCommand(commands.NewBuilderCommand(logger, cfg, packClient))
rootCmd.AddCommand(commands.NewBuildpackCommand(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.NewExtensionCommand(logger, cfg, packClient, buildpackage.NewConfigReader()))
rootCmd.AddCommand(commands.NewConfigCommand(logger, cfg, cfgPath, packClient))
rootCmd.AddCommand(commands.InspectImage(logger, imagewriter.NewFactory(), cfg, packClient))
rootCmd.AddCommand(commands.NewStackCommand(logger))
Expand Down
29 changes: 29 additions & 0 deletions internal/commands/extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

func NewExtensionCommand(logger logging.Logger, cfg config.Config, client PackClient, packageConfigReader PackageConfigReader) *cobra.Command {
cmd := &cobra.Command{
Use: "extension",
Aliases: []string{"extensions"},
Short: "Interact with extensions",
RunE: nil,
}

cmd.AddCommand(ExtensionInspect(logger, cfg, client))
// client and packageConfigReader to be passed later on
cmd.AddCommand(ExtensionPackage(logger, cfg))
// client to be passed later on
cmd.AddCommand(ExtensionNew(logger))
cmd.AddCommand(ExtensionPull(logger, cfg, client))
cmd.AddCommand(ExtensionRegister(logger, cfg, client))
cmd.AddCommand(ExtensionYank(logger, cfg, client))

AddHelpFlag(cmd, "extension")
return cmd
}
41 changes: 41 additions & 0 deletions internal/commands/extension_inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

type ExtensionInspectFlags struct {
Depth int
Registry string
Verbose bool
}

func ExtensionInspect(logger logging.Logger, cfg config.Config, client PackClient) *cobra.Command {
var flags ExtensionInspectFlags
cmd := &cobra.Command{
Use: "inspect <extension-name>",
Args: cobra.ExactArgs(1),
Short: "Show information about an extension",
Example: "pack extension inspect <example-extension>",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
extensionName := args[0]
registry := flags.Registry
if registry == "" {
// fix registry for extension
}

return extensionInspect(logger, extensionName, registry, flags, cfg, client)
}),
}
// flags will be added here
AddHelpFlag(cmd, "inspect")
return cmd
}

func extensionInspect(logger logging.Logger, extensionName, registry string, flags ExtensionInspectFlags, cfg config.Config, client PackClient) error {
// logic to inspect extension
return nil
}
36 changes: 36 additions & 0 deletions internal/commands/extension_new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/pkg/logging"
)

// ExtensionNewFlags define flags provided to the ExtensionNew command
type ExtensionNewFlags struct {
API string
Path string
Stacks []string
Version string
}

// extensioncreator type to be added here and argument also to be added in the function

// ExtensionNew generates the scaffolding of an extension
func ExtensionNew(logger logging.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "new <id>",
Short: "Creates basic scaffolding of an extension",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Example: "pack extension new <example-extension>",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// logic will go here
return nil
}),
}

// flags will go here

AddHelpFlag(cmd, "new")
return cmd
}
38 changes: 38 additions & 0 deletions internal/commands/extension_package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

// ExtensionPackageFlags define flags provided to the ExtensionPackage command
type ExtensionPackageFlags struct {
PackageTomlPath string
Format string
Publish bool
Policy string
ExtensionRegistry string
Path string
}

// Packager and PackageConfigReader to be added here and argument also to be added in the function

// ExtensionPackage packages (a) extension(s) into OCI format, based on a package config
func ExtensionPackage(logger logging.Logger, cfg config.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "package <name> --config <config-path>",
Short: "Package an extension in OCI format",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// logic will be added here
return nil
}),
}

// flags will be added here

AddHelpFlag(cmd, "package")
return cmd
}
31 changes: 31 additions & 0 deletions internal/commands/extension_pull.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

// ExtensionPullFlags consist of flags applicable to the `extension pull` command
type ExtensionPullFlags struct {
// ExtensionRegistry is the name of the extension registry to use to search for
ExtensionRegistry string
}

// ExtensionPull pulls an extension and stores it locally
func ExtensionPull(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Command {
cmd := &cobra.Command{
Use: "pull <uri>",
Args: cobra.ExactArgs(1),
Short: "Pull an extension from a registry and store it locally",
Example: "pack extension pull <extension-example>",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// logic will be added here
return nil
}),
}
// flags will be added here
AddHelpFlag(cmd, "pull")
return cmd
}
28 changes: 28 additions & 0 deletions internal/commands/extension_register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

type ExtensionRegisterFlags struct {
ExtensionRegistry string
}

func ExtensionRegister(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Command {
cmd := &cobra.Command{
Use: "register <image>",
Args: cobra.ExactArgs(1),
Short: "Register an extension to a registry",
Example: "pack extension register <extension-example>",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// logic will be added here
return nil
}),
}
// flags will be added here
AddHelpFlag(cmd, "register")
return cmd
}
51 changes: 51 additions & 0 deletions internal/commands/extension_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package commands_test

import (
"bytes"
"testing"

"github.com/golang/mock/gomock"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/commands/fakes"
"github.com/buildpacks/pack/internal/commands/testmocks"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
h "github.com/buildpacks/pack/testhelpers"
)

func TestExtensionCommand(t *testing.T) {
spec.Run(t, "ExtensionCommand", testExtensionCommand, spec.Parallel(), spec.Report(report.Terminal{}))
}

func testExtensionCommand(t *testing.T, when spec.G, it spec.S) {
var (
cmd *cobra.Command
logger logging.Logger
outBuf bytes.Buffer
mockClient *testmocks.MockPackClient
)

it.Before(func() {
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
mockController := gomock.NewController(t)
mockClient = testmocks.NewMockPackClient(mockController)
cmd = commands.NewExtensionCommand(logger, config.Config{}, mockClient, fakes.NewFakePackageConfigReader())
cmd.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel))
})

when("extension", func() {
it("prints help text", func() {
cmd.SetArgs([]string{})
h.AssertNil(t, cmd.Execute())
output := outBuf.String()
h.AssertContains(t, output, "Interact with extensions")
for _, command := range []string{"Usage", "package", "register", "yank", "pull", "inspect"} {
h.AssertContains(t, output, command)
}
})
})
}
30 changes: 30 additions & 0 deletions internal/commands/extension_yank.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

type ExtensionYankFlags struct {
ExtensionRegistry string
Undo bool
}

func ExtensionYank(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Command {
cmd := &cobra.Command{
Use: "yank <extension-id-and-version>",
Args: cobra.ExactArgs(1),
Short: "Yank an extension from a registry",
Example: "pack yank <extension-example>",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// logic will be added here
return nil
}),
}
// flags will be added here
AddHelpFlag(cmd, "yank")

return cmd
}