Golang Command.Out Examples

Golang Command.Out - 30 examples found. These are the top rated real world Golang examples of github.com/spf13/cobra.Command.Out extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
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")
	}
}
Example #2
0
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")
	}
}
Example #3
0
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)
}
Example #4
0
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")
	}
}
Example #5
0
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
}
Example #6
0
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
}