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

Function LocalNew

cli/cmd/new/newLocal.go:41–102  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, workspaceInfo workspace.WorkspaceInfo,
	yamlExecuteFun func(yamlConfig config.SmartIdeConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string))

Source from the content-addressed store, hash-verified

39)
40
41func LocalNew(cmd *cobra.Command, args []string, workspaceInfo workspace.WorkspaceInfo,
42 yamlExecuteFun func(yamlConfig config.SmartIdeConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string)) {
43
44 // 环境监测
45 err := common.CheckLocalGitEnv() //检测git环境
46 common.CheckError(err)
47 err = common.CheckLocalEnv() //检测docker环境
48 common.CheckError(err)
49
50 // 获取command中的配置
51 selectedTemplateType, err := cmdCommon.GetTemplateSetting(cmd, args)
52 common.CheckError(err)
53 if selectedTemplateType == nil { // 未指定模板类型的时候,提示用户后退出
54 return // 退出
55 }
56
57 // 检测当前文件夹是否有.ide.yaml,有了返回
58 hasIdeConfigYaml := common.IsExist(".ide/.ide.yaml")
59 if hasIdeConfigYaml {
60 common.SmartIDELog.Info("当前目录已经完成初始化,无须再次进行!")
61 }
62
63 // 检测并阻断
64 folderPath, _ := os.Getwd()
65 isEmpty, _ := folderEmpty(folderPath) // 检测当前文件夹是否为空
66 if !isEmpty {
67 isContinue, _ := cmd.Flags().GetBool("yes")
68 if !isContinue { // 如果没有设置yes,那么就要给出提示
69 var s string
70 common.SmartIDELog.Importance(i18nInstance.New.Info_noempty_is_comfirm)
71 fmt.Scanln(&s)
72 if s != "y" {
73 return
74 }
75 } else {
76 common.SmartIDELog.Importance("当前文件夹不为空,当前文件夹内数据将被重置。")
77 }
78 }
79
80 // 复制template 到当前文件夹
81 copyTemplateToCurrentDir(selectedTemplateType.TypeName, selectedTemplateType.SubType)
82
83 // 执行start命令
84 common.SmartIDELog.Info(i18nInstance.Start.Info_start) // 执行start
85 if workspaceInfo.Mode == workspace.WorkingMode_Local {
86 func1 := func(dockerContainerName string, docker common.Docker) {
87 if dockerContainerName != "" {
88 common.SmartIDELog.Info(i18nInstance.New.Info_creating_project)
89 for i := 0; i < len(selectedTemplateType.Commands); i++ {
90 workFolder := fmt.Sprintf("/home/project/%v", workspaceInfo.GetProjectDirctoryName())
91 cmdarr := strings.Split(selectedTemplateType.Commands[i], " ")
92 out, err := docker.Exec(context.Background(), dockerContainerName, workFolder, cmdarr, []string{})
93 common.CheckError(err)
94 common.SmartIDELog.Debug(out)
95 }
96 }
97 }
98 isUnforward, _ := cmd.Flags().GetBool("unforward")

Callers

nothing calls this directly

Calls 8

folderEmptyFunction · 0.85
copyTemplateToCurrentDirFunction · 0.85
IsExistMethod · 0.80
InfoMethod · 0.80
ImportanceMethod · 0.80
ExecMethod · 0.80
DebugMethod · 0.80

Tested by

no test coverage detected