cmd

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   string
	BuildDate string
	GitCommit string
	GitState  string
)
View Source
var BundleDownloadCmd = &cobra.Command{
	Use:   "download",
	Short: "Download a bundle",
	Long: "Download a readonly, non-interactive view of the entire data that is part of a bundle. If --bundle is not specified" +
		" the latest bundle will be downloaded",
	Run: func(cmd *cobra.Command, args []string) {
		var nameFilterRe *regexp.Regexp

		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		destinationStore, err := paramsToDestStore(params, destTEmpty, "")
		if err != nil {
			wrapFatalln("create destination store", err)
			return
		}

		err = setLatestOrLabelledBundle(ctx, remoteStores.meta)
		if err != nil {
			wrapFatalln("determine bundle id", err)
			return
		}
		bd := core.NewBDescriptor()
		bundle := core.New(bd,
			core.Repo(params.repo.RepoName),
			core.MetaStore(remoteStores.meta),
			core.ConsumableStore(destinationStore),
			core.BlobStore(remoteStores.blob),
			core.BundleID(params.bundle.ID),
			core.ConcurrentFileDownloads(
				params.bundle.ConcurrencyFactor/fileDownloadsByConcurrencyFactor),
			core.ConcurrentFilelistDownloads(
				params.bundle.ConcurrencyFactor/filelistDownloadsByConcurrencyFactor),
		)

		if params.bundle.NameFilter != "" {
			nameFilterRe, err = regexp.Compile(params.bundle.NameFilter)
			if err != nil {
				wrapFatalln(fmt.Sprintf("name filter regexp %s didn't build", params.bundle.NameFilter), err)
				return
			}
			err = core.PublishSelectBundleEntries(ctx, bundle, func(name string) (bool, error) {
				return nameFilterRe.MatchString(name), nil
			})
			if err != nil {
				wrapFatalln("publish bundle entries selected by name filter", err)
				return
			}
		} else {
			err = core.Publish(ctx, bundle)
			if err != nil {
				wrapFatalln("publish bundle", err)
				return
			}
		}
	},
}
View Source
var BundleListCommand = &cobra.Command{
	Use:   "list",
	Short: "List bundles",
	Long:  "List the bundles in a repo, ordered by their bundle ID",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		err = core.ListBundlesApply(params.repo.RepoName, remoteStores.meta, applyBundleTemplate,
			core.ConcurrentList(params.core.ConcurrencyFactor),
			core.BatchSize(params.core.BatchSize))
		if err != nil {
			wrapFatalln("concurrent list bundles", err)
			return
		}
	},
}

BundleListCommand describes the CLI command for listing bundles

View Source
var GetBundleCommand = &cobra.Command{
	Use:   "get",
	Short: "Get bundle info by id",
	Long: `Performs a direct lookup of labels by id.
Prints corresponding bundle information if the label exists,
exits with ENOENT status otherwise.`,
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}

		err = setLatestOrLabelledBundle(ctx, remoteStores.meta)
		if err == status.ErrNotFound {
			wrapFatalWithCode(int(unix.ENOENT), "didn't find label %q", params.label.Name)
			return
		}
		if err != nil {
			wrapFatalln("determine bundle id", err)
			return
		}
		bundle := core.New(core.NewBDescriptor(),
			core.Repo(params.repo.RepoName),
			core.MetaStore(remoteStores.meta),
			core.BundleID(params.bundle.ID),
		)

		err = core.DownloadMetadata(ctx, bundle)
		if err == status.ErrNotFound {
			wrapFatalWithCode(int(unix.ENOENT), "didn't find bundle %q", params.bundle.ID)
			return
		}
		if err != nil {
			wrapFatalln("error downloading bundle information", err)
			return
		}

		var buf bytes.Buffer
		err = bundleDescriptorTemplate.Execute(&buf, bundle.BundleDescriptor)
		if err != nil {
			log.Println("executing template:", err)
		}
		log.Println(buf.String())
	},
}
View Source
var GetLabelCommand = &cobra.Command{
	Use:   "get",
	Short: "Get bundle info by label",
	Long: `Performs a direct lookup of labels by name.
Prints corresponding bundle information if the label exists,
exits with ENOENT status otherwise.`,
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		bundle := core.New(core.NewBDescriptor(),
			core.Repo(params.repo.RepoName),
			core.MetaStore(remoteStores.meta),
		)
		label := core.NewLabel(core.NewLabelDescriptor(),
			core.LabelName(params.label.Name),
		)
		err = label.DownloadDescriptor(ctx, bundle, true)
		if err == status.ErrNotFound {
			wrapFatalWithCode(int(unix.ENOENT), "didn't find label %q", params.label.Name)
			return
		}
		if err != nil {
			wrapFatalln("error downloading label information", err)
			return
		}

		var buf bytes.Buffer
		err = labelDescriptorTemplate.Execute(&buf, label.Descriptor)
		if err != nil {
			log.Println("executing template:", err)
		}
		log.Println(buf.String())

	},
}
View Source
var GetRepoCommand = &cobra.Command{
	Use:   "get",
	Short: "Get repo info by name",
	Long: `Performs a direct lookup of repos by name.
Prints corresponding repo information if the name exists,
exits with ENOENT status otherwise.`,
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		repoDescriptor, err := core.GetRepoDescriptorByRepoName(
			remoteStores.meta, params.repo.RepoName)
		if err == status.ErrNotFound {
			wrapFatalWithCode(int(unix.ENOENT), "didn't find repo %q", params.repo.RepoName)
			return
		}
		if err != nil {
			wrapFatalln("error downloading repo information", err)
			return
		}

		var buf bytes.Buffer
		err = repoDescriptorTemplate.Execute(&buf, repoDescriptor)
		if err != nil {
			wrapFatalln("executing template", err)
			return
		}
		log.Println(buf.String())
	},
}
View Source
var LabelListCommand = &cobra.Command{
	Use:   "list",
	Short: "List labels",
	Long:  "List the labels in a repo",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		err = core.ListLabelsApply(params.repo.RepoName, remoteStores.meta, params.label.Prefix, applyLabelTemplate,
			core.ConcurrentList(params.core.ConcurrencyFactor),
			core.BatchSize(params.core.BatchSize))
		if err != nil {
			wrapFatalln("download label list", err)
			return
		}
	},
}

LabelListCommand lists the labels in a repo

View Source
var SetLabelCommand = &cobra.Command{
	Use:   "set",
	Short: "Set labels",
	Long:  "Set the label corresponding to a bundle",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()
		contributor, err := paramsToContributor(params)
		if err != nil {
			wrapFatalln("populate contributor struct", err)
			return
		}
		remoteStores, err := paramsToRemoteCmdStores(ctx, params)
		if err != nil {
			wrapFatalln("create remote stores", err)
			return
		}
		bundle := core.New(core.NewBDescriptor(),
			core.Repo(params.repo.RepoName),
			core.MetaStore(remoteStores.meta),
			core.BundleID(params.bundle.ID),
		)
		bundleExists, err := bundle.Exists(ctx)
		if err != nil {
			wrapFatalln("poll for bundle existence", err)
			return
		}
		if !bundleExists {
			wrapFatalln(fmt.Sprintf("bundle %v not found", bundle), nil)
			return
		}
		labelDescriptor := core.NewLabelDescriptor(
			core.LabelContributor(contributor),
		)
		label := core.NewLabel(labelDescriptor,
			core.LabelName(params.label.Name),
		)
		err = label.UploadDescriptor(ctx, bundle)
		if err != nil {
			wrapFatalln("upload label", err)
			return
		}
	},
}

Functions

func DieIfNotAccessible

func DieIfNotAccessible(path string)

DieIfNotAccessible exits the process if the path is not accessible.

func DieIfNotDirectory

func DieIfNotDirectory(path string)

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

type Config

type Config struct {
	// bug in viper? Need to keep names of fields the same as the serialized names..
	Metadata   string `json:"metadata" yaml:"metadata"`
	Blob       string `json:"blob" yaml:"blob"`
	Credential string `json:"credential" yaml:"credential"`
}

Config describes the CLI configuration.

type DestT

type DestT uint

DestT defines the nomenclature for allowed destination types (e.g. Empty/NonEmpty)

type VersionInfo

type VersionInfo struct {
	Version   string `json:"version,omitempty"`
	BuildDate string `json:"buildDate,omitempty"`
	GitCommit string `json:"gitCommit,omitempty"`
	GitState  string `json:"gitState,omitempty"`
}

func NewVersionInfo

func NewVersionInfo() VersionInfo

func (VersionInfo) String

func (v VersionInfo) String() string

Jump to

Keyboard shortcuts

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