etcdctl/ctlv2/command/set_command.go
func setCommandFunc(c *cli.Context, ki client.KeysAPI) {
	if len(c.Args()) == 0 {
		handleError(c, ExitBadArgs, errors.New("key required"))
	}
	key := c.Args()[0]
	value, err := argOrStdin(c.Args(), os.Stdin, 1)
	if err != nil {
		handleError(c, ExitBadArgs, errors.New("value required"))
	}

	ttl := c.Int("ttl")
	prevValue := c.String("swap-with-value")
	prevIndex := c.Int("swap-with-index")

	ctx, cancel := contextWithTotalTimeout(c)
	resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
	cancel()
	if err != nil {
		handleError(c, ExitServerError, err)
	}

	printResponseKey(resp, c.GlobalString("output"))
}
func setCommandFunc(c *cli.Context, ki client.KeysAPI) {
	if len(c.Args()) == 0 {
		handleError(c, ExitBadArgs, errors.New("key required"))
	}
	key := c.Args()[0]
	value, err := argOrStdin(c.Args(), os.Stdin, 1)
	if err != nil {
		handleError(c, ExitBadArgs, errors.New("value required"))
	}

	ttl := c.Int("ttl")
	prevValue := c.String("swap-with-value")
	prevIndex := c.Int("swap-with-index")

	ctx, cancel := contextWithTotalTimeout(c)
	resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
	cancel()
	if err != nil {
		handleError(c, ExitServerError, err)
	}

	printResponseKey(resp, c.GlobalString("output"))
}
func setCommandFunc ( c * cli . Context , ki client . KeysAPI ) { if len ( c . Args ( ) ) == 0 { handleError ( c , ExitBadArgs , errors . New ( " " ) ) } key := c . Args ( ) [ 0 ] value , err := argOrStdin ( c . Args ( ) , os . Stdin , 1 ) if err != nil { handleError ( c , ExitBadArgs , errors . New ( " " ) ) } ttl := c . Int ( " " ) prevValue := c . String ( " " ) prevIndex := c . Int ( " " ) ctx , cancel := contextWithTotalTimeout ( c ) resp , err := ki . Set ( ctx , key , value , & client . SetOptions { TTL : time . Duration ( ttl ) * time . Second , PrevIndex : uint64 ( prevIndex ) , PrevValue : prevValue } ) cancel ( ) if err != nil { handleError ( c , ExitServerError , err ) } printResponseKey ( resp , c . GlobalString ( " " ) ) }
// setCommandFunc executes the "set" command.
setCommandFunc executes the set command .