Example #1
0
// FetchRepo will download the boilerplate from remote and extract to ${appName}/ folder
func FetchRepo(t int, appName string, appID string) error {
	utils.CheckError(os.Mkdir(appName, 0700))

	repoURL := map[int]string{
		Python: "http://lcinternal-cloud-code-update.leanapp.cn/python-getting-started.zip",
		NodeJS: "http://lcinternal-cloud-code-update.leanapp.cn/node-js-getting-started.zip",
	}[t]

	dir, err := ioutil.TempDir("", "leanengine")
	utils.CheckError(err)
	defer os.RemoveAll(dir)

	log.Println("正在下载项目模版...")

	resp, err := grequests.Get(repoURL, nil)
	if err != nil {
		return err
	}
	defer resp.Close()
	if resp.StatusCode != 200 {
		return errors.New(utils.FormatServerErrorResult(resp.String()))
	}

	log.Println("下载完成")

	zipFilePath := filepath.Join(dir, "getting-started.zip")
	resp.DownloadToFile(zipFilePath)

	log.Println("正在创建项目...")

	zipFile, err := zip.OpenReader(zipFilePath)
	utils.CheckError(err)
	defer zipFile.Close()
	for _, f := range zipFile.File {
		err := extractAndWriteFile(f, appName)
		if err != nil {
			return err
		}
	}

	if err := apps.AddApp(appName, appName, appID); err != nil {
		return err
	}

	log.Println("创建项目完成")

	return nil
}
Example #2
0
func appAddAction(c *cli.Context) {
	var appName, appID string
	wizard.Ask([]wizard.Question{
		{
			Content: "请输入应用名:",
			Input: &wizard.Input{
				Hidden: false,
				Result: &appName,
			},
		},
		{
			Content: "请输入应用 appID:",
			Input: &wizard.Input{
				Hidden: false,
				Result: &appID,
			},
		},
	})

	utils.CheckError(apps.AddApp("", appName, appID))
	utils.CheckError(apps.SwitchApp("", appName))
	log.Println("已切换至应用:" + appName)
}