本文整理汇总了Golang中github.com/spf13/cobra.Command.Out方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Out方法的具体用法?Golang Command.Out怎么用?Golang Command.Out使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Out方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: inspectImages
func inspectImages(ctx *cobra.Command, args []string) {
if len(args) < 1 {
ErrorExit(ctx, "Needs an argument <NAME[:TAG]|ID> at least to inspect")
}
docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
if err != nil {
log.Fatal(err)
}
var images []api.ImageInfo
var gotError = false
for _, name := range args {
if imageInfo, err := docker.InspectImage(name); err != nil {
log.Error(err)
gotError = true
} else {
images = append(images, *imageInfo)
}
}
if len(images) > 0 {
if err := FormatPrint(ctx.Out(), images); err != nil {
log.Fatal(err)
}
}
if gotError {
log.Fatal("Error: failed to inspect one or more images")
}
}
示例2: inspectVolumes
func inspectVolumes(ctx *cobra.Command, args []string) {
if len(args) < 1 {
ErrorExit(ctx, "Needs an argument <ID|CONTAINER-NAME:PATH> at least to inspect")
}
volumes, err := getVolumes(ctx)
if err != nil {
log.Fatal(err)
}
var _volumes Volumes
var gotError = false
for _, arg := range args {
if volume := volumes.Find(arg); volume == nil {
log.Errorf("No such volume: %s", arg)
gotError = true
} else {
_volumes = append(_volumes, volume)
}
}
if len(_volumes) > 0 {
if err := FormatPrint(ctx.Out(), _volumes); err != nil {
log.Fatal(err)
}
}
if gotError {
log.Fatal("Error: failed to inspect one or more volumes")
}
}
示例3: tagImage
func tagImage(ctx *cobra.Command, args []string) {
if len(args) < 2 {
ErrorExit(ctx, "Needs two arguments <NAME[:TAG]|ID> <NEW-NAME[:TAG]>")
}
reg, name, tag, err := client.ParseRepositoryName(args[1])
if err != nil {
log.Fatal(err)
}
if reg != "" {
name = reg + "/" + name
}
docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
if err != nil {
log.Fatal(err)
}
if err := docker.TagImage(args[0], name, tag, boolForce); err != nil {
log.Fatal(err)
}
ctx.Printf("Tagged %s as %s:%s\n", args[0], name, tag)
}
示例4: inspectContainers
func inspectContainers(ctx *cobra.Command, args []string) {
if len(args) < 1 {
ErrorExit(ctx, "Needs an argument <NAME|ID> at least to inspect")
}
docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
if err != nil {
log.Fatal(err)
}
var containers []api.ContainerInfo
var gotError = false
for _, name := range args {
if containerInfo, err := docker.InspectContainer(name); err != nil {
log.Error(err)
gotError = true
} else {
containers = append(containers, *containerInfo)
}
}
if len(containers) > 0 {
if err := FormatPrint(ctx.Out(), containers); err != nil {
log.Fatal(err)
}
}
if gotError {
log.Fatal("Error: failed to inspect one or more containers")
}
}
示例5: checkChaincodeCmdParams
func checkChaincodeCmdParams(cmd *cobra.Command) error {
if chaincodeName == undefinedParamValue {
if chaincodePath == undefinedParamValue {
err := fmt.Sprintf("Error: must supply value for %s path parameter.\n", chainFuncName)
cmd.Out().Write([]byte(err))
cmd.Usage()
return errors.New(err)
}
}
if chaincodeCtorJSON != "{}" {
// Check to ensure the JSON has "function" and "args" keys
input := &pb.ChaincodeMessage{}
jsonerr := json.Unmarshal([]byte(chaincodeCtorJSON), &input)
if jsonerr != nil {
err := fmt.Sprintf("Error: must supply 'function' and 'args' keys in %s constructor parameter.\n", chainFuncName)
cmd.Out().Write([]byte(err))
cmd.Usage()
return errors.New(err)
}
}
return nil
}
示例6: certList
func (c *certCommander) certList(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
cmd.Usage()
return fmt.Errorf("")
}
config, err := c.configGetter()
if err != nil {
return err
}
trustDir := config.GetString("trust_dir")
certPath := filepath.Join(trustDir, notary.TrustedCertsDir)
// Load all individual (non-CA) certificates that aren't expired and don't use SHA1
certStore, err := trustmanager.NewX509FilteredFileStore(
certPath,
trustmanager.FilterCertsExpiredSha1,
)
if err != nil {
return fmt.Errorf("Failed to create a new truststore with directory: %s", trustDir)
}
trustedCerts := certStore.GetCertificates()
cmd.Println("")
prettyPrintCerts(trustedCerts, cmd.Out())
cmd.Println("")
return nil
}
示例7: pullImage
func pullImage(ctx *cobra.Command, args []string) {
if len(args) < 1 {
ErrorExit(ctx, "Needs an argument <NAME[:TAG]> to pull")
}
reg, name, tag, err := client.ParseRepositoryName(args[0])
if err != nil {
log.Fatal(err)
}
repository := name + ":" + tag
if boolAll {
repository = name
}
if reg != "" {
repository = reg + "/" + repository
}
docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
if err != nil {
log.Fatal(err)
}
if _, err := docker.PullImage(repository); err != nil {
log.Fatal(err)
}
}
示例8: setupAppConfig
func setupAppConfig(f *clientcmd.Factory, out io.Writer, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
dockerClient, _, err := dockerutil.NewHelper().GetClient()
if err == nil {
if err = dockerClient.Ping(); err == nil {
config.SetDockerClient(dockerClient)
}
}
if err != nil {
glog.V(2).Infof("No local Docker daemon detected: %v", err)
}
osclient, _, err := f.Clients()
if err != nil {
return err
}
config.SetOpenShiftClient(osclient, namespace)
config.Out = out
config.ErrOut = c.Out()
unknown := config.AddArguments(args)
if len(unknown) != 0 {
return cmdutil.UsageError(c, "Did not recognize the following arguments: %v", unknown)
}
if config.AllowMissingImages && config.AsSearch {
return cmdutil.UsageError(c, "--allow-missing-images and --search are mutually exclusive.")
}
return nil
}
示例9: Complete
// Complete sets any default behavior for the command
func (o *NewAppOptions) Complete(commandName string, f *clientcmd.Factory, c *cobra.Command, args []string, out io.Writer) error {
o.Out = out
o.ErrOut = c.Out()
o.Output = kcmdutil.GetFlagString(c, "output")
// Only output="" should print descriptions of intermediate steps. Everything
// else should print only some specific output (json, yaml, go-template, ...)
if len(o.Output) == 0 {
o.Config.Out = o.Out
} else {
o.Config.Out = ioutil.Discard
}
o.Config.ErrOut = o.ErrOut
o.Action.Out, o.Action.ErrOut = o.Out, o.ErrOut
o.Action.Bulk.Mapper = clientcmd.ResourceMapper(f)
o.Action.Bulk.Op = configcmd.Create
// Retry is used to support previous versions of the API server that will
// consider the presence of an unknown trigger type to be an error.
o.Action.Bulk.Retry = retryBuildConfig
o.Config.DryRun = o.Action.DryRun
o.CommandPath = c.CommandPath()
o.CommandName = commandName
mapper, _ := f.Object(false)
o.PrintObject = cmdutil.VersionedPrintObject(f.PrintObject, c, mapper, out)
o.LogsForObject = f.LogsForObject
if err := CompleteAppConfig(o.Config, f, c, args); err != nil {
return err
}
if err := setAppConfigLabels(c, o.Config); err != nil {
return err
}
return nil
}
示例10: tufList
func (t *tufCommander) tufList(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("Must specify a GUN")
}
config, err := t.configGetter()
if err != nil {
return err
}
gun := args[0]
rt, err := getTransport(config, gun, true)
if err != nil {
return err
}
nRepo, err := notaryclient.NewNotaryRepository(
config.GetString("trust_dir"), gun, getRemoteTrustServer(config), rt, t.retriever)
if err != nil {
return err
}
// Retrieve the remote list of signed targets, prioritizing the passed-in list over targets
roles := append(t.roles, data.CanonicalTargetsRole)
targetList, err := nRepo.ListTargets(roles...)
if err != nil {
return err
}
prettyPrintTargets(targetList, cmd.Out())
return nil
}
示例11: runScramble
func runScramble(cmd *cobra.Command, args []string) {
globalFlags(cmd)
t1 := time.Now()
dir, err := ioutil.ReadDir(filepath.Join(graphdir, "graph"))
if err != nil {
logrus.Fatalf("Error reading graph dir: %s", err)
}
var ids = []string{}
for _, v := range dir {
id := v.Name()
if len(id) != 64 {
logrus.Debugf("Skipping: %s", v.Name())
continue
}
cacheDir, err := getCacheDir(id)
if err != nil {
if err == ErrNeedMigration {
logrus.Debugf("%s not migrated", id)
}
logrus.Fatalf("Error getting image IDs: %s", err)
}
if _, err := os.Stat(cacheDir); err != nil {
if os.IsNotExist(err) {
logrus.Debugf("Skipping, missing cache dir: %s", id)
continue
}
logrus.Fatalf("Error checking cache dir %s: %s", cacheDir, err)
}
ids = append(ids, id)
}
updates := map[string]string{}
fileUpdates := []string{
filepath.Join(graphdir, fmt.Sprintf("repositories-%s", driver)),
}
for _, id := range ids {
fmt.Fprintf(cmd.Out(), "Scrambling %s\n", id)
newID := stringid.GenerateRandomID()
updates[id] = newID
oldPath := filepath.Join(graphdir, "graph", id)
newPath := filepath.Join(graphdir, "graph", newID)
if err := os.Rename(oldPath, newPath); err != nil {
logrus.Errorf("Error renaming %s to %s: %s", oldPath, newPath, err)
continue
}
updates[id] = newID
fileUpdates = append(fileUpdates, filepath.Join(graphdir, "graph", newID, "json"))
}
updateReferences(updates, fileUpdates)
logrus.Debugf("Ran scramble in %s", time.Since(t1).String())
}
示例12: setupAppConfig
func setupAppConfig(f *clientcmd.Factory, out io.Writer, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
dockerClient, _, err := dockerutil.NewHelper().GetClient()
if err == nil {
if err = dockerClient.Ping(); err == nil {
config.SetDockerClient(dockerClient)
} else {
glog.V(4).Infof("Docker client did not respond to a ping: %v", err)
}
}
if err != nil {
glog.V(2).Infof("No local Docker daemon detected: %v", err)
}
osclient, kclient, err := f.Clients()
if err != nil {
return err
}
config.KubeClient = kclient
config.SetOpenShiftClient(osclient, namespace)
// Only output="" should print descriptions of intermediate steps. Everything
// else should print only some specific output (json, yaml, go-template, ...)
output := cmdutil.GetFlagString(c, "output")
if len(output) == 0 {
config.Out = out
} else {
config.Out = ioutil.Discard
}
config.ErrOut = c.Out()
if config.AllowSecretUse {
cfg, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
config.SecretAccessor = newConfigSecretRetriever(cfg)
}
unknown := config.AddArguments(args)
if len(unknown) != 0 {
return cmdutil.UsageError(c, "Did not recognize the following arguments: %v", unknown)
}
if config.AllowMissingImages && config.AsSearch {
return cmdutil.UsageError(c, "--allow-missing-images and --search are mutually exclusive.")
}
if len(config.SourceImage) != 0 && len(config.SourceImagePath) == 0 {
return cmdutil.UsageError(c, "--source-image-path must be specified when --source-image is specified.")
}
if len(config.SourceImage) == 0 && len(config.SourceImagePath) != 0 {
return cmdutil.UsageError(c, "--source-image must be specified when --source-image-path is specified.")
}
return nil
}
示例13: getContainerChanges
func getContainerChanges(ctx *cobra.Command, args []string) {
if len(args) < 1 {
ErrorExit(ctx, "Needs an argument <NAME|ID> to get changes")
}
docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
if err != nil {
log.Fatal(err)
}
changes, err := docker.GetContainerChanges(args[0])
if err != nil {
log.Fatal(err)
}
for _, change := range changes {
var kind string
switch change.Kind {
case api.CHANGE_TYPE_MODIFY:
kind = "C"
case api.CHANGE_TYPE_ADD:
kind = "A"
case api.CHANGE_TYPE_DELETE:
kind = "D"
}
ctx.Printf("%s %s\n", kind, change.Path)
}
}
示例14: Complete
// Complete sets any default behavior for the command
func (o *NewAppOptions) Complete(commandName string, f *clientcmd.Factory, c *cobra.Command, args []string, out io.Writer) error {
o.Out = out
o.ErrOut = c.Out()
o.Output = kcmdutil.GetFlagString(c, "output")
// Only output="" should print descriptions of intermediate steps. Everything
// else should print only some specific output (json, yaml, go-template, ...)
if len(o.Output) == 0 {
o.Config.Out = o.Out
} else {
o.Config.Out = ioutil.Discard
}
o.Config.ErrOut = o.ErrOut
o.CommandPath = c.CommandPath()
o.CommandName = commandName
o.PrintObject = cmdutil.VersionedPrintObject(f.PrintObject, c, out)
o.LogsForObject = f.LogsForObject
if err := CompleteAppConfig(o.Config, f, c, args); err != nil {
return err
}
if err := setAppConfigLabels(c, o.Config); err != nil {
return err
}
return nil
}
示例15: keyRemove
// keyRemove deletes a private key based on ID
func (k *keyCommander) keyRemove(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("must specify the key ID of the key to remove")
}
config, err := k.configGetter()
if err != nil {
return err
}
ks, err := k.getKeyStores(config, true, false)
if err != nil {
return err
}
keyID := args[0]
// This is an invalid ID
if len(keyID) != notary.SHA256HexSize {
return fmt.Errorf("invalid key ID provided: %s", keyID)
}
cmd.Println("")
err = removeKeyInteractively(ks, keyID, k.input, cmd.Out())
cmd.Println("")
return err
}