gf/g/os/gcmd/gcmd_value.go

33 lines
974 B
Go
Raw Normal View History

2019-04-11 09:05:27 +08:00
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
//
package gcmd
import "github.com/gogf/gf/g/container/gvar"
// GetAll returns all values as a slice of string.
func (c *gCmdValue) GetAll() []string {
return c.values
}
// Get returns value by index <index> as string,
// if value does not exist, then returns <def>.
func (c *gCmdValue) Get(index int, def...string) string {
if index < len(c.values) {
return c.values[index]
} else if len(def) > 0 {
return def[0]
}
return ""
}
2019-05-10 13:38:06 +08:00
// GetVar returns value by index <index> as *gvar.Var object,
2019-04-11 09:05:27 +08:00
// if value does not exist, then returns <def> as its default value.
2019-05-10 13:38:06 +08:00
func (c *gCmdValue) GetVar(index int, def...string) *gvar.Var {
2019-05-11 18:47:35 +08:00
return gvar.New(c.Get(index, def...), true)
2019-04-11 09:05:27 +08:00
}