MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / printWorkspaces

Function printWorkspaces

cli/cmd/list.go:56–133  ·  view source on GitHub ↗

打印 service 列表

(cliRunningEnv workspace.CliRunningEvnEnum)

Source from the content-addressed store, hash-verified

54
55// 打印 service 列表
56func printWorkspaces(cliRunningEnv workspace.CliRunningEvnEnum) {
57 workspaceInfos, err := dal.GetWorkspaceList()
58 common.CheckError(err)
59
60 auth, err := workspace.GetCurrentUser()
61 common.CheckError(err)
62 if auth != (model.Auth{}) && auth.Token != "" {
63 // 从api 获取workspace
64 serverWorkSpaces, err := workspace.GetServerWorkspaceList(auth, cliRunningEnv)
65
66 if err != nil { // 有错误仅给警告
67 common.SmartIDELog.Importance("从服务器获取工作区列表失败," + err.Error())
68 } else { //
69 workspaceInfos = append(workspaceInfos, serverWorkSpaces...)
70 }
71 }
72 if len(workspaceInfos) <= 0 {
73 common.SmartIDELog.Info(i18nInstance.List.Info_dal_none)
74 return
75 }
76 w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
77 fmt.Fprintln(w, i18nInstance.List.Info_workspace_list_header)
78
79 // 等于标题字符的长度
80 tmpArray := strings.Split(i18nInstance.List.Info_workspace_list_header, "\t")
81 outputArray := []string{}
82 for _, str := range tmpArray {
83 chars := ""
84 for i := 0; i < len(str); i++ {
85 chars += "-"
86 }
87 outputArray = append(outputArray, chars)
88 }
89 fmt.Fprintln(w, strings.Join(outputArray, "\t"))
90
91 // 内容
92 for _, worksapceInfo := range workspaceInfos {
93 dir := worksapceInfo.WorkingDirectoryPath
94 if len(dir) <= 0 {
95 dir = "-"
96 }
97 configFile := worksapceInfo.ConfigFileRelativePath
98 if len(configFile) <= 0 {
99 configFile = "-"
100 } else {
101 if strings.Index(configFile, ".ide") == 0 ||
102 strings.Index(configFile, "/.ide") == 0 ||
103 strings.Index(configFile, "\\.ide") == 0 {
104 configFile = filepath.Base(configFile)
105 }
106 }
107 createTime := ""
108 if worksapceInfo.Mode != workspace.WorkingMode_Local {
109 local, _ := time.LoadLocation("Local") // 北京时区
110 createTime = worksapceInfo.CreatedTime.In(local).Format("2006-01-02 15:04:05") // 格式化输出
111 } else {
112 createTime = worksapceInfo.CreatedTime.Format("2006-01-02 15:04:05") // 格式化输出
113 }

Callers 2

reset.goFile · 0.85
list.goFile · 0.85

Calls 6

ImportanceMethod · 0.80
InfoMethod · 0.80
GetDescMethod · 0.80
ErrorMethod · 0.45
JoinMethod · 0.45
BaseMethod · 0.45

Tested by

no test coverage detected