github.com/zhongdalu/gf@v1.0.0/g/os/gcmd/gcmd_option.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 // 7 8 package gcmd 9 10 import "github.com/zhongdalu/gf/g/container/gvar" 11 12 // GetAll returns all option values as map[string]string. 13 func (c *gCmdOption) GetAll() map[string]string { 14 return c.options 15 } 16 17 // Get returns the option value string specified by <key>, 18 // if value dose not exist, then returns <def>. 19 func (c *gCmdOption) Get(key string, def ...string) string { 20 if option, ok := c.options[key]; ok { 21 return option 22 } else if len(def) > 0 { 23 return def[0] 24 } 25 return "" 26 } 27 28 // GetVar returns the option value as *gvar.Var object specified by <key>, 29 // if value does not exist, then returns <def> as its default value. 30 func (c *gCmdOption) GetVar(key string, def ...string) *gvar.Var { 31 return gvar.New(c.Get(key, def...), true) 32 }