Skip to content

Commit

Permalink
WIP: added required flag scafflod
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 a2b862c commit c4c23ba
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 0 deletions.
39 changes: 39 additions & 0 deletions internal/commands/manifest_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package commands

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

// ManifestAddFlags define flags provided to the ManifestAdd
type ManifestAddFlags struct {
ManifestAnnotateFlags
all bool
}

// ManifestAdd modifies a manifest list (Image index) and add a new image to the list of manifests.
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),
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`,
Long: `manifest add modifies a manifest list (Image index) and add a new image to the list of manifests.
When a manifest list exits locally, user can add a new image to the manifest list using this command`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

cmd.Flags().BoolVar(&flags.all, "all", false, "add all of the contents to the local list (applies only if <manifest> is an index)")
cmd.Flags().StringVar(&flags.os, "os", "", "Set the operating system")
cmd.Flags().StringVar(&flags.arch, "arch", "", "Set the architecture")
cmd.Flags().StringVar(&flags.variant, "variant", "", "Set the architecture variant")

AddHelpFlag(cmd, "add")
return cmd
}
1 change: 1 addition & 0 deletions internal/commands/manifest_add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands_test
37 changes: 37 additions & 0 deletions internal/commands/manifest_annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

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

// ManifestAnnotateFlags define flags provided to the ManifestAnnotate
type ManifestAnnotateFlags struct {
os, arch, variant string
}

// ManifestAnnotate modifies a manifest list (Image index) and update the platform information for an image included in the manifest list.
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),
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`,
Long: `manifest annotate modifies a manifest list (Image index) and update the platform information for an image included in the manifest list.
Sometimes a manifest list could reference an image that doesn't specify the architecture, The "annotate" command allows users to update those values before pushing the manifest list a registry`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

cmd.Flags().StringVar(&flags.os, "os", "", "Set the architecture")
cmd.Flags().StringVar(&flags.arch, "arch", "", "Set the architecture")
cmd.Flags().StringVar(&flags.variant, "variant", "", "Set the architecture")

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

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

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

// ManifestCreate creates an image-index/image-list for a multi-arch image
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),
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 \
cnbs/sample-package:hello-universe-windows`,
Long: `Create a manifest list or manifest index for the image to support muti architecture for the image, it create a new ManifestList or ManifestIndex with the given name/repoName and adds the list of Manifests to the newly created ManifestIndex or ManifestList
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 {
return nil
}),
}

cmd.Flags().StringVarP(&flags.format, "format", "f", "", "Format to save image index as ('OCI' or 'V2S2') (default 'v2s2')")
cmd.Flags().BoolVar(&flags.insecure, "insecure", false, "Allow publishing to insecure registry")
cmd.Flags().BoolVar(&flags.publish, "publish", false, "Publish to registry")
cmd.Flags().StringVarP(&flags.registry, "registry", "r", "", "Publish to registry")

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

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

// ManifestInspectFlags define flags provided to the ManifestInspect
// type ManifestInspectFlags struct {
// }

// ManifestInspect shows the manifest information stored in local storage
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",
Example: `pack manifest inspect cnbs/sample-builder:multiarch`,
Long: `manifest inspect shows the manifest information stored in local storage.
The inspect command will help users to view how their local manifest list looks like`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

AddHelpFlag(cmd, "inspect")
return cmd
}
1 change: 1 addition & 0 deletions internal/commands/manifest_inspect_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands_test
37 changes: 37 additions & 0 deletions internal/commands/manifest_push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

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

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

// ManifestPush pushes a manifest list (Image index) to a registry.
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.",
Example: `pack manifest push cnbs/sample-package:hello-multiarch-universe`,
Long: `manifest push pushes a manifest list (Image index) to a registry.
Once a manifest list is ready to be published into the registry, the push command can be used`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

cmd.Flags().StringVarP(&flags.format, "format", "f", "", "Format to save image index as ('OCI' or 'V2S2') (default 'v2s2')")
cmd.Flags().BoolVar(&flags.insecure, "insecure", false, "Allow publishing to insecure registry")
cmd.Flags().BoolVar(&flags.purge, "purge", false, "Delete the manifest list or image index from local storage if pushing succeeds")

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

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

// ManifestDeleteFlags define flags provided to the ManifestDelete
// type ManifestDeleteFlags struct {
// }

// ManifestDelete deletes one or more manifest lists from local storage
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",
Example: `pack manifest remove cnbs/sample-package:hello-multiarch-universe`,
Long: `Delete one or more manifest lists from local storage.
When a manifest list exits locally, users can remove existing images from a manifest list`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

AddHelpFlag(cmd, "remove")
return cmd
}
1 change: 1 addition & 0 deletions internal/commands/manifest_remove_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands_test
32 changes: 32 additions & 0 deletions internal/commands/manifest_rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package commands

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

// ManifestRemoveFlags define flags provided to the ManifestRemove
// type ManifestRemoveFlags struct {
// }

// ManifestRemove will remove the specified image manifest if it is already referenced in the index
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),
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`,
Long: `manifest rm will remove the specified image manifest if it is already referenced in the index.
Sometimes users can just experiment with the feature locally and they want to discard all the local information created by pack. 'rm' command just delete the local manifest list`,
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
return nil
}),
}

AddHelpFlag(cmd, "rm")
return cmd
}
1 change: 1 addition & 0 deletions internal/commands/manifest_rm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands_test

0 comments on commit c4c23ba

Please sign in to comment.