Example #1
0
// ListTemplates lists all the Gauge templates available in GaugeTemplatesURL
func ListTemplates() {
	templatesURL := config.GaugeTemplatesUrl()
	_, err := common.UrlExists(templatesURL)
	if err != nil {
		logger.Fatalf("Gauge templates URL is not reachable: %s", err.Error())
	}
	tempDir := common.GetTempDir()
	defer util.Remove(tempDir)
	templatesPage, err := util.Download(templatesURL, tempDir, "", true)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Error occurred while downloading templates list: %s", err.Error())
	}

	templatePageContents, err := common.ReadFileContents(templatesPage)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Failed to read contents of file %s: %s", templatesPage, err.Error())
	}
	templates := getTemplateNames(templatePageContents)
	for _, template := range templates {
		logger.Info(template)
	}
	logger.Info("\nRun `gauge --init <template_name>` to create a new Gauge project.")
}
Example #2
0
func getInstallDescription(plugin string, silent bool) (*installDescription, InstallResult) {
	versionInstallDescriptionJSONFile := plugin + "-install.json"
	versionInstallDescriptionJSONUrl, result := constructPluginInstallJSONURL(plugin)
	if !result.Success {
		return nil, installError(fmt.Errorf("Could not construct plugin install json file URL. %s", result.Error))
	}
	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)

	downloadedFile, downloadErr := util.Download(versionInstallDescriptionJSONUrl, tempDir, versionInstallDescriptionJSONFile, silent)
	if downloadErr != nil {
		logger.Debug("Failed to download %s file: %s", versionInstallDescriptionJSONFile, downloadErr)
		return nil, installError(fmt.Errorf("Invalid plugin. Could not download %s file.", versionInstallDescriptionJSONFile))
	}

	return getInstallDescriptionFromJSON(downloadedFile)
}
Example #3
0
func installPluginVersion(installDesc *installDescription, versionInstallDescription *versionInstallDescription) InstallResult {
	if common.IsPluginInstalled(installDesc.Name, versionInstallDescription.Version) {
		return installSkipped(fmt.Sprintf("Plugin %s %s is already installed.", installDesc.Name, versionInstallDescription.Version))
	}

	downloadLink, err := getDownloadLink(versionInstallDescription.DownloadUrls)
	if err != nil {
		return installError(fmt.Errorf("Could not get download link: %s", err.Error()))
	}

	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	logger.Info("Downloading %s", filepath.Base(downloadLink))
	pluginZip, err := util.Download(downloadLink, tempDir, "", false)
	if err != nil {
		return installError(fmt.Errorf("Failed to download the plugin. %s", err.Error()))
	}
	return InstallPluginFromZipFile(pluginZip, installDesc.Name)
}