get

package
v1.0.0-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package get contains libraries for fetching packages.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Git contains information about the git repo to fetch
	Git *kptfilev1.Git

	// Destination is the output directory to clone the package to.  Defaults to the name of the package --
	// either the base repo name, or the base subdirectory name.
	Destination string

	// Name is the name to give the package.  Defaults to the destination.
	Name string

	// UpdateStrategy is the strategy that will be configured in the package
	// Kptfile. This determines how changes will be merged when updating the
	// package.
	UpdateStrategy kptfilev1.UpdateStrategyType
}

Command fetches a package from a git repository, copies it to a local directory, and expands any remote subpackages.

Example
package main

import (
	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{Git: &kptfilev1.Git{
		Repo: "https://github.com/example-org/example-repo",
		Ref:  "v1.0",
	}}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

Example (Branch)
package main

import (
	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{Git: &kptfilev1.Git{
		Repo: "https://github.com/example-org/example-repo",
		Ref:  "refs/heads/v1.0",
	}}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

Example (Commit)
package main

import (
	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{Git: &kptfilev1.Git{
		Repo: "https://github.com/example-org/example-repo",
		Ref:  "8186bef8e5c0621bf80fa8106bd595aae8b62884",
	}}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

Example (Destination)
package main

import (
	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{
		Git: &kptfilev1.Git{
			Repo: "https://github.com/example-org/example-repo",
			Ref:  "v1.0",
		},
		Destination: "destination-dir"}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

Example (Subdir)
package main

import (
	"path/filepath"

	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{
		Git: &kptfilev1.Git{
			Repo:      "https://github.com/example-org/example-repo",
			Ref:       "v1.0",
			Directory: filepath.Join("path", "to", "package"),
		},
	}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

Example (Tag)
package main

import (
	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
	"github.com/GoogleContainerTools/kpt/internal/util/get"

	kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
)

func main() {
	err := get.Command{Git: &kptfilev1.Git{
		Repo: "https://github.com/example-org/example-repo",
		Ref:  "refs/tags/v1.0",
	}}.Run(fake.CtxWithDefaultPrinter())
	if err != nil {
		// handle error
	}
}
Output:

func (*Command) DefaultValues

func (c *Command) DefaultValues() error

DefaultValues sets values to the default values if they were unspecified

func (Command) Run

func (c Command) Run(ctx context.Context) error

Run runs the Command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL