Skip to content

Commit

Permalink
WIP: added required client go files
Browse files Browse the repository at this point in the history
Signed-off-by: WYGIN <[email protected]>
  • Loading branch information
WYGIN committed Oct 28, 2023
1 parent c4c23ba commit 1a750a3
Show file tree
Hide file tree
Showing 33 changed files with 248 additions and 44 deletions.
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
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.NewManifestCommand(logger, packClient))
rootCmd.AddCommand(commands.InspectImage(logger, imagewriter.NewFactory(), cfg, packClient))
rootCmd.AddCommand(commands.NewStackCommand(logger))
rootCmd.AddCommand(commands.Rebase(logger, cfg, packClient))
Expand Down
7 changes: 7 additions & 0 deletions internal/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ type PackClient interface {
InspectImage(string, bool) (*client.ImageInfo, error)
Rebase(context.Context, client.RebaseOptions) error
CreateBuilder(context.Context, client.CreateBuilderOptions) error
CreateManifest(context.Context, string, []string) (imageID string, err error)
AnnotateManifest() error
AddManifest() error
DeleteManifest() error
RemoveManifest() error
PushManifest() error
InspectManifest() error
NewBuildpack(context.Context, client.NewBuildpackOptions) error
PackageBuildpack(ctx context.Context, opts client.PackageBuildpackOptions) error
PackageExtension(ctx context.Context, opts client.PackageBuildpackOptions) error
Expand Down
26 changes: 26 additions & 0 deletions internal/commands/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package commands

import (
"github.com/spf13/cobra"

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

func NewManifestCommand(logger logging.Logger, client PackClient) *cobra.Command {
cmd := &cobra.Command{
Use: "manifest",
Short: "Interact with image index or manifest list",
RunE: nil,
}

cmd.AddCommand(ManifestCreate(logger, client))
cmd.AddCommand(ManifestAdd(logger, client))
cmd.AddCommand(ManifestAnnotate(logger, client))
cmd.AddCommand(ManifestDelete(logger, client))
cmd.AddCommand(ManifestInspect(logger, client))
cmd.AddCommand(ManifestPush(logger, client))
cmd.AddCommand(ManifestRemove(logger, client))

AddHelpFlag(cmd, "builder")
return cmd

Check warning on line 25 in internal/commands/manifest.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest.go#L9-L25

Added lines #L9 - L25 were not covered by tests
}
9 changes: 5 additions & 4 deletions internal/commands/manifest_add.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestAddFlags define flags provided to the ManifestAdd
Expand All @@ -16,8 +17,8 @@ func ManifestAdd(logger logging.Logger, pack PackClient) *cobra.Command {
var flags ManifestAddFlags

cmd := &cobra.Command{
Use: "pack manifest add [OPTIONS] <manifest-list> <manifest> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Use: "pack manifest add [OPTIONS] <manifest-list> <manifest> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Short: "manifest add modifies a manifest list (Image index) and add a new image to the list of manifests.",
Example: `pack manifest add cnbs/sample-package:hello-multiarch-universe \
cnbs/sample-package:hello-universe-riscv-linux`,
Expand All @@ -36,4 +37,4 @@ func ManifestAdd(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "add")
return cmd

Check warning on line 39 in internal/commands/manifest_add.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_add.go#L33-L39

Added lines #L33 - L39 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_add_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
9 changes: 5 additions & 4 deletions internal/commands/manifest_annotate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestAnnotateFlags define flags provided to the ManifestAnnotate
Expand All @@ -15,8 +16,8 @@ func ManifestAnnotate(logger logging.Logger, pack PackClient) *cobra.Command {
var flags ManifestAnnotateFlags

cmd := &cobra.Command{
Use: "pack manifest annotate [OPTIONS] <manifest-list> <manifest> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Use: "pack manifest annotate [OPTIONS] <manifest-list> <manifest> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Short: "manifest annotate modifies a manifest list (Image index) and update the platform information for an image included in the manifest list.",
Example: `pack manifest annotate cnbs/sample-package:hello-universe-multiarch \
cnbs/sample-package:hello-universe --arch amd64`,
Expand All @@ -34,4 +35,4 @@ func ManifestAnnotate(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "annotate")
return cmd

Check warning on line 37 in internal/commands/manifest_annotate.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_annotate.go#L32-L37

Added lines #L32 - L37 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_annotate_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
24 changes: 19 additions & 5 deletions internal/commands/manifest_create.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestCreateFlags define flags provided to the ManifestCreate
type ManifestCreateFlags struct {
format, registry string
format, registry string
insecure, publish bool
}

Expand All @@ -16,8 +17,8 @@ func ManifestCreate(logger logging.Logger, pack PackClient) *cobra.Command {
var flags ManifestCreateFlags

cmd := &cobra.Command{
Use: "pack manifest create <manifest-list> <manifest> [<manifest> ... ] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Use: "pack manifest create <manifest-list> <manifest> [<manifest> ... ] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Short: "manifest create generates a manifest list for a multi-arch image",
Example: `pack manifest create cnbs/sample-package:hello-multiarch-universe \
cnbs/sample-package:hello-universe \
Expand All @@ -27,6 +28,19 @@ func ManifestCreate(logger logging.Logger, pack PackClient) *cobra.Command {
If the <manifest-list> already exists in the registry: pack will save a local copy of the remote manifest list,
If the <manifest-list> doestn't exist in a registry: pack will create a local representation of the manifest list that will only save on the remote registry if the user publish it`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
// manifestList := args[0]
// manifests := args[1:]

// if cmd.Flags().Changed("insecure") {
// flags.insecure = !flags.insecure
// }

// if cmd.Flags().Changed("publish") {
// flags.publish = !flags.publish
// }

// id, err := pack.CreateManifest()

return nil
}),

Check warning on line 45 in internal/commands/manifest_create.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_create.go#L16-L45

Added lines #L16 - L45 were not covered by tests
}
Expand All @@ -38,4 +52,4 @@ func ManifestCreate(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "create")
return cmd

Check warning on line 54 in internal/commands/manifest_create.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_create.go#L48-L54

Added lines #L48 - L54 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_create_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
11 changes: 6 additions & 5 deletions internal/commands/manifest_inspect.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestInspectFlags define flags provided to the ManifestInspect
Expand All @@ -14,9 +15,9 @@ func ManifestInspect(logger logging.Logger, pack PackClient) *cobra.Command {
// var flags ManifestInspectFlags

cmd := &cobra.Command{
Use: "pack manifest inspect <manifest-list> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Short: "manifest inspect shows the manifest information stored in local storage",
Use: "pack manifest inspect <manifest-list> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Short: "manifest inspect shows the manifest information stored in local storage",
Example: `pack manifest inspect cnbs/sample-builder:multiarch`,
Long: `manifest inspect shows the manifest information stored in local storage.
Expand All @@ -28,4 +29,4 @@ func ManifestInspect(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "inspect")
return cmd

Check warning on line 31 in internal/commands/manifest_inspect.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_inspect.go#L30-L31

Added lines #L30 - L31 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_inspect_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
13 changes: 7 additions & 6 deletions internal/commands/manifest_push.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestPushFlags define flags provided to the ManifestPush
type ManifestPushFlags struct {
format string
format string
insecure, purge bool
}

Expand All @@ -16,9 +17,9 @@ func ManifestPush(logger logging.Logger, pack PackClient) *cobra.Command {
var flags ManifestPushFlags

cmd := &cobra.Command{
Use: "pack manifest push [OPTIONS] <manifest-list> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Short: "manifest push pushes a manifest list (Image index) to a registry.",
Use: "pack manifest push [OPTIONS] <manifest-list> [flags]",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Short: "manifest push pushes a manifest list (Image index) to a registry.",
Example: `pack manifest push cnbs/sample-package:hello-multiarch-universe`,
Long: `manifest push pushes a manifest list (Image index) to a registry.
Expand All @@ -34,4 +35,4 @@ func ManifestPush(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "push")
return cmd

Check warning on line 37 in internal/commands/manifest_push.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_push.go#L32-L37

Added lines #L32 - L37 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_push_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
11 changes: 6 additions & 5 deletions internal/commands/manifest_remove.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestDeleteFlags define flags provided to the ManifestDelete
Expand All @@ -14,9 +15,9 @@ func ManifestDelete(logger logging.Logger, pack PackClient) *cobra.Command {
// var flags ManifestDeleteFlags

cmd := &cobra.Command{
Use: "pack manifest remove [manifest-list] [manifest-list...] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
Short: "Delete one or more manifest lists from local storage",
Use: "pack manifest remove [manifest-list] [manifest-list...] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
Short: "Delete one or more manifest lists from local storage",
Example: `pack manifest remove cnbs/sample-package:hello-multiarch-universe`,
Long: `Delete one or more manifest lists from local storage.
Expand All @@ -28,4 +29,4 @@ func ManifestDelete(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "remove")
return cmd

Check warning on line 31 in internal/commands/manifest_remove.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_remove.go#L30-L31

Added lines #L30 - L31 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_remove_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
9 changes: 5 additions & 4 deletions internal/commands/manifest_rm.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package commands

import (
"github.com/buildpacks/pack/pkg/logging"
"github.com/spf13/cobra"

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

// ManifestRemoveFlags define flags provided to the ManifestRemove
Expand All @@ -14,8 +15,8 @@ func ManifestRemove(logger logging.Logger, pack PackClient) *cobra.Command {
// var flags ManifestRemoveFlags

cmd := &cobra.Command{
Use: "pack manifest rm [manifest-list] [manifest] [manifest...] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Use: "pack manifest rm [manifest-list] [manifest] [manifest...] [flags]",
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Short: "manifest rm will remove the specified image manifest if it is already referenced in the index",
Example: `pack manifest rm cnbs/sample-package:hello-multiarch-universe \
cnbs/sample-package:hello-universe-windows`,
Expand All @@ -29,4 +30,4 @@ func ManifestRemove(logger logging.Logger, pack PackClient) *cobra.Command {

AddHelpFlag(cmd, "rm")
return cmd

Check warning on line 32 in internal/commands/manifest_rm.go

View check run for this annotation

Codecov / codecov/patch

internal/commands/manifest_rm.go#L31-L32

Added lines #L31 - L32 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion internal/commands/manifest_rm_test.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package commands_test
package commands_test
Loading

0 comments on commit 1a750a3

Please sign in to comment.