获取工作区id
(cmd *cobra.Command, args []string)
| 56 | |
| 57 | // 获取工作区id |
| 58 | func GetWorkspaceIdFromFlagsOrArgs(cmd *cobra.Command, args []string) string { |
| 59 | fflags := cmd.Flags() |
| 60 | |
| 61 | // 从args 或者 flag 中获取值 |
| 62 | if len(args) > 0 { // 从args中加载 |
| 63 | tmpWorkspaceId := args[0] |
| 64 | checkFlagUnnecessary(fflags, flag_workspaceid, tmpWorkspaceId) |
| 65 | |
| 66 | // 是否为数字,或者包含sw |
| 67 | if common.IsNumber(tmpWorkspaceId) || strings.Index(strings.ToLower(tmpWorkspaceId), "ws") == 1 { |
| 68 | return tmpWorkspaceId |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // 从 workspaceid 参数中加载 |
| 73 | if fflags.Changed(flag_workspaceid) { // 从flag中加载 |
| 74 | tmpWorkspaceId, err := fflags.GetString(flag_workspaceid) |
| 75 | common.CheckError(err) |
| 76 | tmpWorkspaceId = strings.TrimSpace(tmpWorkspaceId) |
| 77 | |
| 78 | // 是否为数字,或者包含sw |
| 79 | if common.IsNumber(tmpWorkspaceId) || strings.Index(strings.ToLower(tmpWorkspaceId), "ws") == 1 { |
| 80 | return tmpWorkspaceId |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // 从 serverworkspaceid 参数中获取 |
| 85 | if fflags.Changed("serverworkspaceid") { // 从flag中加载 |
| 86 | serverWorkspaceId, err := fflags.GetString("serverworkspaceid") |
| 87 | common.CheckError(err) |
| 88 | serverWorkspaceId = strings.TrimSpace(serverWorkspaceId) |
| 89 | |
| 90 | // 是否为数字,或者包含sw |
| 91 | if common.IsNumber(serverWorkspaceId) || strings.Index(strings.ToLower(serverWorkspaceId), "ws") == 1 { |
| 92 | return serverWorkspaceId |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return "" |
| 97 | } |
| 98 | |
| 99 | // 从start command的flag、args中获取workspace |
| 100 | func GetWorkspaceFromCmd(cmd *cobra.Command, args []string) (workspaceInfo workspace.WorkspaceInfo, err error) { |
no test coverage detected