mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
First iteration of support for Java
This commit is contained in:
committed by
Matthew Gilliard
parent
82d612a754
commit
cd0b68dfb7
35
fn/init.go
35
fn/init.go
@@ -31,6 +31,7 @@ var (
|
||||
".rs": "rust",
|
||||
".cs": "dotnet",
|
||||
".fs": "dotnet",
|
||||
".java": "java",
|
||||
}
|
||||
|
||||
fnInitRuntimes []string
|
||||
@@ -104,11 +105,20 @@ func (a *initFnCmd) init(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
runtimeSpecified := a.runtime != ""
|
||||
|
||||
err := a.buildFuncFile(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if runtimeSpecified {
|
||||
err := a.generateBoilerplate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var ffmt *string
|
||||
if a.format != "" {
|
||||
ffmt = &a.format
|
||||
@@ -135,6 +145,20 @@ func (a *initFnCmd) init(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *initFnCmd) generateBoilerplate() error {
|
||||
helper := langs.GetLangHelper(a.runtime)
|
||||
if helper != nil && helper.HasBoilerplate() {
|
||||
if err := helper.GenerateBoilerplate(); err != nil {
|
||||
if err == langs.ErrBoilerplateExists {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
fmt.Println("function boilerplate generated.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *initFnCmd) buildFuncFile(c *cli.Context) error {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -190,9 +214,14 @@ func (a *initFnCmd) buildFuncFile(c *cli.Context) error {
|
||||
|
||||
func detectRuntime(path string) (runtime string, err error) {
|
||||
for ext, runtime := range fileExtToRuntime {
|
||||
fn := filepath.Join(path, fmt.Sprintf("func%s", ext))
|
||||
if exists(fn) {
|
||||
return runtime, nil
|
||||
filenames := []string {
|
||||
filepath.Join(path, fmt.Sprintf("func%s", ext)),
|
||||
filepath.Join(path, fmt.Sprintf("Func%s", ext)),
|
||||
}
|
||||
for _, filename := range filenames {
|
||||
if exists(filename) {
|
||||
return runtime, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no supported files found to guess runtime, please set runtime explicitly with --runtime flag.")
|
||||
|
||||
Reference in New Issue
Block a user