示例#1
0
文件: project.go 项目: elizar/apex
// LoadFunctions reads the ./functions directory, populating the Functions field.
// If no `names` are specified, all functions are loaded.
func (p *Project) LoadFunctions(names ...string) error {
	dir := filepath.Join(p.Path, functionsDir)
	p.Log.Debugf("loading functions in %s", dir)

	existing, err := p.FunctionDirNames()
	if err != nil {
		return err
	}

	if len(names) == 0 {
		names = existing
	}

	for _, name := range names {
		if !utils.ContainsString(existing, name) {
			p.Log.Warnf("function %q does not exist in project", name)
			continue
		}

		fn, err := p.LoadFunction(name)
		if err != nil {
			return err
		}

		p.Functions = append(p.Functions, fn)
	}

	if len(p.Functions) == 0 {
		return errors.New("no function loaded")
	}

	return nil
}
示例#2
0
// output (deduped) functions.
func functions(args []string) {
	files, err := ioutil.ReadDir("functions")
	if err != nil {
		return
	}

	for _, file := range files {
		if !utils.ContainsString(args, file.Name()) {
			fmt.Printf("%s ", file.Name())
		}
	}
}
示例#3
0
func Test_ContainsString(t *testing.T) {
	assert.True(t, utils.ContainsString([]string{"a", "b"}, "a"))
	assert.False(t, utils.ContainsString([]string{"a", "b"}, "c"))
}