获取工作区id
(cmd *cobra.Command, args []string)
| 72 | |
| 73 | // 获取工作区id |
| 74 | func getHostIdFromFlagsAndArgs(cmd *cobra.Command, args []string) int { |
| 75 | fflags := cmd.Flags() |
| 76 | |
| 77 | // 从args 或者 flag 中获取值 |
| 78 | var hostId int |
| 79 | if len(args) > 0 { // 从args中加载 |
| 80 | str := args[0] |
| 81 | tmpHostId, err := strconv.Atoi(str) |
| 82 | if err == nil && tmpHostId > 0 { |
| 83 | hostId = tmpHostId |
| 84 | } |
| 85 | |
| 86 | } else if fflags.Changed(flag_hostid) { // 从flag中加载 |
| 87 | tmpHostId, err := fflags.GetInt32(flag_hostid) |
| 88 | common.CheckError(err) |
| 89 | if tmpHostId > 0 { |
| 90 | hostId = int(tmpHostId) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return hostId |
| 95 | } |
| 96 | |
| 97 | func init() { |
| 98 | HostGetCmd.Flags().Int32P("hostid", "r", 0, i18nInstance.Host.Info_help_flag_hostid) |
no outgoing calls
no test coverage detected