github.com/landoop/schema-registry@v0.0.0-20190327143759-50a5701c1891/schema-registry-cli/cmd/exists.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  var existsCmd = &cobra.Command{
    10  	Use:   "exists <subject>",
    11  	Short: "checks if the schema provided through stdin exists for the subject",
    12  	Long:  ``,
    13  	RunE: func(cmd *cobra.Command, args []string) error {
    14  		if len(args) != 1 {
    15  			return fmt.Errorf("expected 1 argument")
    16  		}
    17  		isreg, sch, err := assertClient().IsRegistered(args[0], stdinToString())
    18  		if err != nil {
    19  			return err
    20  		}
    21  		fmt.Printf("exists: %v\n", isreg)
    22  		if isreg {
    23  			fmt.Printf("id: %d\n", sch.ID)
    24  			fmt.Printf("version: %d\n", sch.Version)
    25  		}
    26  		return nil
    27  	},
    28  }
    29  
    30  func init() {
    31  	RootCmd.AddCommand(existsCmd)
    32  }