func (p *ReadKeySubcommand) Parse(arguments []string) error {
	err := cmd.ParseFlagsWithConfig(p.FlagSet, arguments, DefaultConfigPath, ServiceName)
	if err != nil {
		return err
	}
	args := p.FlagSet.Args()
	if len(args) < 1 {
		log.Errorf("\"%s\" command requires key kind", CmdReadKey)
		return ErrMissingKeyKind
	}
	if len(args) > 1 {
		log.Errorf("\"%s\" command does not support more than one key kind", CmdReadKey)
		return ErrMultipleKeyKinds
	}
	coarseKind, id, err := ParseKeyKind(args[0])
	if err != nil {
		return err
	}
	switch coarseKind {
	case KeyTransportConnector, KeyTransportServer, KeyTransportTranslator:
		p.readKeyKind = coarseKind
		p.contextID = id
	case KeyPoisonKeypair:
		if err := p.validateKeyParts(); err != nil {
			return err
		}
		if p.private {
			p.readKeyKind = KeyPoisonPrivate
		} else {
			p.readKeyKind = KeyPoisonPublic
		}
	case KeyStorageKeypair:
		if err := p.validateKeyParts(); err != nil {
			return err
		}
		if p.private {
			p.readKeyKind = KeyStoragePrivate
		} else {
			p.readKeyKind = KeyStoragePublic
		}
		p.contextID = id
	case KeyZoneKeypair:
		if err := p.validateKeyParts(); err != nil {
			return err
		}
		if p.private {
			p.readKeyKind = KeyZonePrivate
		} else {
			p.readKeyKind = KeyZonePublic
		}
		p.contextID = id
	default:
		return ErrUnknownKeyKind
	}
	return nil
}
Parse command-line parameters of the subcommand.
package keys
import (
	"errors"
	"flag"
	"fmt"
	"os"
	"github.com/cossacklabs/acra/cmd"
	"github.com/cossacklabs/acra/keystore"
	log "github.com/sirupsen/logrus"
)
var SupportedReadKeyKinds = []string{
	KeyPoisonPublic,
	KeyPoisonPrivate,
	KeyStoragePublic,
	KeyStoragePrivate,
	KeyZonePublic,
	KeyZonePrivate,
}
var (
	ErrMissingClientID = errors.New("client ID not specified")
	ErrMissingZoneID   = errors.New("zone ID not specified")
	ErrUnknownKeyKind  = errors.New("unknown key kind")
	ErrMissingKeyPart  = errors.New("key part not specified")
	ErrExtraKeyPart    = errors.New("both key parts specified")
)
type ReadKeyParams interface {
	ReadKeyKind() string
	ClientID() []byte
	ZoneID() []byte
}
type ReadKeySubcommand struct {
	CommonKeyStoreParameters
	FlagSet *flag.FlagSet
	public, private bool
	readKeyKind string
	contextID   []byte
}
func (p *ReadKeySubcommand) Name() string {
	return CmdReadKey
}
func (p *ReadKeySubcommand) GetFlagSet() *flag.FlagSet {
	return p.FlagSet
}
func (p *ReadKeySubcommand) RegisterFlags() {
	p.FlagSet = flag.NewFlagSet(CmdReadKey, flag.ContinueOnError)
	p.CommonKeyStoreParameters.Register(p.FlagSet)
	p.FlagSet.BoolVar(&p.public, "public", false, "read public key of the keypair")
	p.FlagSet.BoolVar(&p.private, "private", false, "read private key of the keypair")
	p.FlagSet.Usage = func() {
		fmt.Fprintf(os.Stderr, "Command \"%s\": read and print key material in plaintext\n", CmdReadKey)
		fmt.Fprintf(os.Stderr, "\n\t%s %s [options...] <key-ID>\n\n", os.Args[0], CmdReadKey)
		fmt.Fprintf(os.Stderr, "\nOptions:\n")
		cmd.PrintFlags(p.FlagSet)
	}
}