当前位置: 首页>>代码示例>>Golang>>正文


Golang common.ReadFileContents函数代码示例

本文整理汇总了Golang中github.com/getgauge/common.ReadFileContents函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadFileContents函数的具体用法?Golang ReadFileContents怎么用?Golang ReadFileContents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ReadFileContents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ParseFile

func (parser *ConceptParser) ParseFile(file string) ([]*Step, *ParseDetailResult) {
	fileText, fileReadErr := common.ReadFileContents(file)
	if fileReadErr != nil {
		return nil, &ParseDetailResult{Error: &ParseError{Message: fmt.Sprintf("failed to read concept file %s", file)}}
	}
	return parser.Parse(fileText)
}
开发者ID:krwhitney,项目名称:gauge,代码行数:7,代码来源:conceptParser.go

示例2: ListTemplates

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

	templatePageContents, err := common.ReadFileContents(templatesPage)
	if err != nil {
		fmt.Printf("Failed to read contents of file %s: %s\n", templatesPage, err.Error())
		os.Exit(1)
	}
	templates := getTemplateNames(templatePageContents)
	for _, template := range templates {
		fmt.Println(template)
	}
	fmt.Println("\nRun `gauge --init <template_name>` to create a new Gauge project.")
}
开发者ID:andrewmkrug,项目名称:gauge,代码行数:27,代码来源:init.go

示例3: ListTemplates

// 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.")
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:26,代码来源:init.go

示例4: writeConceptToFile

func writeConceptToFile(concept string, conceptUsageText string, conceptFileName string, fileName string, info *gauge_messages.TextInfo) {
	if _, err := os.Stat(conceptFileName); os.IsNotExist(err) {
		os.Create(conceptFileName)
	}
	content, _ := common.ReadFileContents(conceptFileName)
	util.SaveFile(conceptFileName, content+"\n"+concept, true)
	text := ReplaceExtractedStepsWithConcept(info, conceptUsageText)
	util.SaveFile(fileName, text, true)
}
开发者ID:andrewmkrug,项目名称:gauge,代码行数:9,代码来源:concept_extractor.go

示例5: getInstallDescriptionFromJSON

func getInstallDescriptionFromJSON(installJSON string) (*installDescription, installResult) {
	InstallJSONContents, readErr := common.ReadFileContents(installJSON)
	if readErr != nil {
		return nil, installError(readErr.Error())
	}
	installDescription := &installDescription{}
	if err := json.Unmarshal([]byte(InstallJSONContents), installDescription); err != nil {
		return nil, installError(err.Error())
	}
	return installDescription, installSuccess("")
}
开发者ID:0-T-0,项目名称:gauge,代码行数:11,代码来源:install.go

示例6: installRunnerFromDir

func installRunnerFromDir(unzippedPluginDir string, language string) error {
	var r runner.Runner
	contents, err := common.ReadFileContents(filepath.Join(unzippedPluginDir, language+jsonExt))
	if err != nil {
		return err
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return err
	}
	return copyPluginFilesToGaugeInstallDir(unzippedPluginDir, r.Id, r.Version)
}
开发者ID:krwhitney,项目名称:gauge,代码行数:12,代码来源:install.go

示例7: ExtractConcept

func ExtractConcept(conceptName *gauge_messages.Step, steps []*gauge_messages.Step, conceptFileName string, changeAcrossProject bool, selectedTextInfo *gauge_messages.TextInfo) (bool, error, []string) {
	content := SPEC_HEADING_TEMPLATE
	if util.IsSpec(selectedTextInfo.GetFileName()) {
		content, _ = common.ReadFileContents(selectedTextInfo.GetFileName())
	}
	concept, conceptUsageText, err := getExtractedConcept(conceptName, steps, content)
	if err != nil {
		return false, err, []string{}
	}
	writeConceptToFile(concept, conceptUsageText, conceptFileName, selectedTextInfo.GetFileName(), selectedTextInfo)
	return true, errors.New(""), []string{conceptFileName, selectedTextInfo.GetFileName()}
}
开发者ID:andrewmkrug,项目名称:gauge,代码行数:12,代码来源:concept_extractor.go

示例8: getRunnerJSONContents

func getRunnerJSONContents(file string) (*runner.Runner, error) {
	var r runner.Runner
	contents, err := common.ReadFileContents(file)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return nil, err
	}
	return &r, nil
}
开发者ID:0-T-0,项目名称:gauge,代码行数:12,代码来源:install.go

示例9: GetPluginDescriptorFromJSON

func GetPluginDescriptorFromJSON(pluginJSON string) (*pluginDescriptor, error) {
	pluginJSONContents, err := common.ReadFileContents(pluginJSON)
	if err != nil {
		return nil, err
	}
	var pd pluginDescriptor
	if err = json.Unmarshal([]byte(pluginJSONContents), &pd); err != nil {
		return nil, fmt.Errorf("%s: %s", pluginJSON, err.Error())
	}
	pd.pluginPath = filepath.Dir(pluginJSON)

	return &pd, nil
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:13,代码来源:plugin.go

示例10: initializePredefinedResolvers

func initializePredefinedResolvers() map[string]resolverFn {
	return map[string]resolverFn{
		"file": func(filePath string) (*gauge.StepArg, error) {
			fileContent, err := common.ReadFileContents(util.GetPathToFile(filePath))
			if err != nil {
				return nil, err
			}
			return &gauge.StepArg{Value: fileContent, ArgType: gauge.SpecialString}, nil
		},
		"table": func(filePath string) (*gauge.StepArg, error) {
			csv, err := common.ReadFileContents(util.GetPathToFile(filePath))
			if err != nil {
				return nil, err
			}
			csvTable, err := convertCsvToTable(csv)
			if err != nil {
				return nil, err
			}
			return &gauge.StepArg{Table: *csvTable, ArgType: gauge.SpecialTable}, nil
		},
	}
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:22,代码来源:resolver.go

示例11: getPluginDescriptorFromJson

func getPluginDescriptorFromJson(pluginJson string) (*pluginDescriptor, error) {
	pluginJsonContents, err := common.ReadFileContents(pluginJson)
	if err != nil {
		return nil, err
	}
	var pd pluginDescriptor
	if err = json.Unmarshal([]byte(pluginJsonContents), &pd); err != nil {
		return nil, errors.New(fmt.Sprintf("%s: %s", pluginJson, err.Error()))
	}
	pd.pluginPath = filepath.Dir(pluginJson)

	return &pd, nil
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:13,代码来源:plugin.go

示例12: initializePredefinedResolvers

func initializePredefinedResolvers() map[string]resolverFn {
	return map[string]resolverFn{
		"file": func(filePath string) (*stepArg, error) {
			fileContent, err := common.ReadFileContents(filePath)
			if err != nil {
				return nil, err
			}
			return &stepArg{value: fileContent, argType: specialString}, nil
		},
		"table": func(filePath string) (*stepArg, error) {
			csv, err := common.ReadFileContents(filePath)
			if err != nil {
				return nil, err
			}
			csvTable, err := convertCsvToTable(csv)
			if err != nil {
				return nil, err
			}
			return &stepArg{table: *csvTable, argType: specialTable}, nil
		},
	}
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:22,代码来源:resolver.go

示例13: getLanguageJSONFilePath

func getLanguageJSONFilePath(manifest *manifest.Manifest, r *Runner) (string, error) {
	languageJsonFilePath, err := common.GetLanguageJSONFilePath(manifest.Language)
	if err != nil {
		return "", err
	}
	contents, err := common.ReadFileContents(languageJsonFilePath)
	if err != nil {
		return "", err
	}
	err = json.Unmarshal([]byte(contents), r)
	if err != nil {
		return "", err
	}
	return filepath.Dir(languageJsonFilePath), nil
}
开发者ID:krwhitney,项目名称:gauge,代码行数:15,代码来源:runner.go

示例14: AddConcepts

func AddConcepts(conceptFile string, conceptDictionary *ConceptDictionary) *ParseError {
	fileText, fileReadErr := common.ReadFileContents(conceptFile)
	if fileReadErr != nil {
		return &ParseError{Message: fmt.Sprintf("failed to read concept file %s", conceptFile)}
	}
	concepts, parseResults := new(ConceptParser).Parse(fileText)
	if parseResults != nil && parseResults.Warnings != nil {
		for _, warning := range parseResults.Warnings {
			logger.Log.Warning(warning.String())
		}
	}
	if parseResults != nil && parseResults.Error != nil {
		return parseResults.Error
	}
	return conceptDictionary.Add(concepts, conceptFile)
}
开发者ID:ranjeet-floyd,项目名称:gauge,代码行数:16,代码来源:conceptParser.go

示例15: IsCompatibleLanguagePluginInstalled

func IsCompatibleLanguagePluginInstalled(name string) bool {
	jsonFilePath, err := common.GetLanguageJSONFilePath(name)
	if err != nil {
		return false
	}
	var r runner.Runner
	contents, err := common.ReadFileContents(jsonFilePath)
	if err != nil {
		return false
	}
	err = json.Unmarshal([]byte(contents), &r)
	if err != nil {
		return false
	}
	return (version.CheckCompatibility(version.CurrentGaugeVersion, &r.GaugeVersionSupport) == nil)
}
开发者ID:krwhitney,项目名称:gauge,代码行数:16,代码来源:install.go


注:本文中的github.com/getgauge/common.ReadFileContents函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。