本文整理匯總了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)
}
示例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.")
}
示例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.")
}
示例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)
}
示例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("")
}
示例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)
}
示例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()}
}
示例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
}
示例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
}
示例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
},
}
}
示例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
}
示例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
},
}
}
示例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
}
示例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)
}
示例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)
}