From 5bc987a5e90a5fca4f419545a4924cc7c5a4e73d Mon Sep 17 00:00:00 2001 From: skothari-tibco Date: Fri, 6 Sep 2019 08:53:28 -0400 Subject: [PATCH 1/3] Add examples plugin --- examples/.DS_Store | Bin 0 -> 6148 bytes examples/app/rest.json | 71 ++++++++++++++++++++++++++++++++++++ examples/commands/create.go | 62 +++++++++++++++++++++++++++++++ examples/commands/list.go | 64 ++++++++++++++++++++++++++++++++ examples/examples.go | 24 ++++++++++++ examples/go.mod | 9 +++++ examples/go.sum | 24 ++++++++++++ 7 files changed, 254 insertions(+) create mode 100644 examples/.DS_Store create mode 100644 examples/app/rest.json create mode 100644 examples/commands/create.go create mode 100644 examples/commands/list.go create mode 100644 examples/examples.go create mode 100644 examples/go.mod create mode 100644 examples/go.sum diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..da07aa6853bb7b7687f6e861317c0d52c61a4ec7 GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHN0A&|z{CXm!~^gR7ES*H$5cmnB-G%I%Z zD|S`@Z2$T80!#olbXV*=%*>dtaK;_?uhYl%a=X5>;#J@&VrHyNnC;iLL0pQvfVyTmjO&;ssLc!1UOG})p;=82 zR;?Ceh}WZ?+UmMqI#RP8R>OzYoz15hnq@nzF`-!xQ4j$Um=RcIKKc27r2jVm&svm< zfC&6E0=7P!4tu^-ovjbA=k?dB`g+i*aXG_}p8zI)6mRKa+;6_1_R^8c3Qa!(fk8n8 H{*=Hspa&6( literal 0 HcmV?d00001 diff --git a/examples/app/rest.json b/examples/app/rest.json new file mode 100644 index 0000000..078962b --- /dev/null +++ b/examples/app/rest.json @@ -0,0 +1,71 @@ +{ + "name": "RestApp", + "type": "flogo:app", + "version": "0.0.1", + "description": "My flogo application description", + "appModel": "1.1.0", + "imports": [ + "github.com/project-flogo/contrib@latest:/activity/log", + "github.com/project-flogo/contrib@latest:/trigger/rest", + "github.com/project-flogo/flow@latest" + ], + "triggers": [ + { + "id": "my_rest_trigger", + "ref": "#rest", + "settings": { + "port": "8888" + }, + "handlers": [ + { + "settings": { + "method": "GET", + "path": "/test/:val" + }, + "actions": [ + { + "ref": "#flow", + "settings": { + "flowURI": "res://flow:simple_flow" + }, + "input": { + "in": "=$.pathParams.val" + } + } + ] + } + ] + } + ], + "resources": [ + { + "id": "flow:simple_flow", + "data": { + "name": "simple_flow", + "metadata": { + "input": [ + { "name": "in", "type": "string", "value": "test" } + ], + "output": [ + { "name": "out", "type": "string" } + ] + }, + "tasks": [ + { + "id": "log", + "name": "Log Message", + "activity": { + "ref": "#log", + "input": { + "message": "=$flow.in", + "flowInfo": "false", + "addToFlow": "false" + } + } + } + ], + "links": [] + } + } + ] + } \ No newline at end of file diff --git a/examples/commands/create.go b/examples/commands/create.go new file mode 100644 index 0000000..393aea8 --- /dev/null +++ b/examples/commands/create.go @@ -0,0 +1,62 @@ +package commands + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + + "github.com/project-flogo/cli/api" + "github.com/project-flogo/cli/util" + "github.com/spf13/cobra" +) + +var appName string +var flogoJsonPath string +var goPath = os.Getenv("GOPATH") +var examplePath = filepath.Join("github.com", "project-flogo", "cli-plugins", "examples", "app") + +var CreateCmd = &cobra.Command{ + Use: "create", + Short: "Create Command ", + Long: `This command helps you to work flogo contributions `, + PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Run: func(cmd *cobra.Command, args []string) { + if len(args) > 0 { + appName = args[0] + } else { + fmt.Fprintf(os.Stderr, "Please provide the App name \n") + os.Exit(1) + } + + currentDir, err := os.Getwd() + if err != nil { + fmt.Fprintf(os.Stderr, "Error determining working directory: %v\n", err) + os.Exit(1) + } + + if !strings.HasPrefix(appName, "http") { + //Install the example dir in GOPATH/src + + err := util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) + if err != nil { + fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) + os.Exit(1) + } + + flogoJsonPath = filepath.Join(goPath, "src", examplePath, appName+".json") + + if _, err := os.Stat(flogoJsonPath); os.IsNotExist(err) { + fmt.Fprintf(os.Stderr, "Please provide the Valid App name") + os.Exit(1) + } + } + + _, err = api.CreateProject(currentDir, appName, flogoJsonPath, "") + if err != nil { + fmt.Fprintf(os.Stderr, "Error creating project: %v\n", err) + os.Exit(1) + } + }, +} diff --git a/examples/commands/list.go b/examples/commands/list.go new file mode 100644 index 0000000..5a06c2a --- /dev/null +++ b/examples/commands/list.go @@ -0,0 +1,64 @@ +package commands + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + + "text/tabwriter" + + "github.com/project-flogo/cli/util" + "github.com/spf13/cobra" +) + +var ListAppCmd = &cobra.Command{ + Use: "list", + Short: "List Contributions Command ", + Long: `This command helps you to find flogo contributions `, + PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Run: func(cmd *cobra.Command, args []string) { + + currentDir, err := os.Getwd() + if err != nil { + fmt.Fprintf(os.Stderr, "Error determining working directory: %v\n", err) + os.Exit(1) + } + + err = util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) + if err != nil { + fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) + os.Exit(1) + } + + var result []string + if _, err := os.Stat(filepath.Join(goPath, "src", examplePath)); os.IsNotExist(err) { + fmt.Fprintf(os.Stderr, "Error listing examples directory %v", err) + os.Exit(1) + } + err = filepath.Walk(filepath.Join(goPath, "src", examplePath), func(path string, info os.FileInfo, err error) error { + if !info.IsDir() { + result = append(result, info.Name()) + } + + return nil + }) + + if err != nil { + fmt.Errorf("%v", err) + os.Exit(1) + } + + w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug) + fmt.Fprintln(w, "Name\tDescription") + + for key, val := range result { + if key == 10 { + break + } + + fmt.Fprintf(w, "%v\t \n", val[:len(val)-5]) + } + w.Flush() + }, +} diff --git a/examples/examples.go b/examples/examples.go new file mode 100644 index 0000000..d4f0eb2 --- /dev/null +++ b/examples/examples.go @@ -0,0 +1,24 @@ +package examples + +import ( + "github.com/project-flogo/cli-plugins/examples/commands" + "github.com/project-flogo/cli/common" + + "github.com/spf13/cobra" +) + +var exmpCmd = &cobra.Command{ + Use: "example", + Short: "Developer tool for basic work ", + Long: `This command helps you to work flogo contributions `, + PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Run: func(cmd *cobra.Command, args []string) { + }, +} + +func init() { + exmpCmd.AddCommand(commands.CreateCmd) + exmpCmd.AddCommand(commands.ListAppCmd) + common.RegisterPlugin(exmpCmd) + +} diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..ca3a094 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,9 @@ +module github.com/project-flogo/cli-plugins/examples + +go 1.12 + +require ( + github.com/project-flogo/cli v0.9.0 + github.com/spf13/cobra v0.0.3 + github.com/spf13/pflag v1.0.3 // indirect +) diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..e30f581 --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,24 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/msoap/byline v1.1.1 h1:imxWvm9wIHNGePF/peiOxcL1vgVLK3/qKsMW75XZn9c= +github.com/msoap/byline v1.1.1/go.mod h1:E2oCrXddpzrmu4NmrwEv4Qiyweo62Yp3+w3IN3X2sq8= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/project-flogo/cli v0.9.0 h1:TvcH+ObMRp9NgcqW1UuXHRqbYTBLfchN4rTNBb1/h0o= +github.com/project-flogo/cli v0.9.0/go.mod h1:8oeuq6QK6f4vh8rzTNTcTg1AsX7oMiS7O07LWOF0yzs= +github.com/project-flogo/core v0.9.0 h1:/iR4m5L0zj5SuqLtDDZIRyvrvG8TxwxdM0n8ZURo1I4= +github.com/project-flogo/core v0.9.0/go.mod h1:QGWi7TDLlhGUaYH3n/16ImCuulbEHGADYEXyrcHhX7U= +github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= +go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= From e9010a0eb9c6b8fce82b0076a731bd68a2e30128 Mon Sep 17 00:00:00 2001 From: skothari-tibco Date: Fri, 6 Sep 2019 09:05:39 -0400 Subject: [PATCH 2/3] Edit --- examples/commands/create.go | 15 +++------------ examples/commands/list.go | 23 ++++------------------- examples/examples.go | 31 +++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/examples/commands/create.go b/examples/commands/create.go index 393aea8..89daae3 100644 --- a/examples/commands/create.go +++ b/examples/commands/create.go @@ -3,12 +3,10 @@ package commands import ( "fmt" "os" - "os/exec" "path/filepath" "strings" "github.com/project-flogo/cli/api" - "github.com/project-flogo/cli/util" "github.com/spf13/cobra" ) @@ -18,10 +16,9 @@ var goPath = os.Getenv("GOPATH") var examplePath = filepath.Join("github.com", "project-flogo", "cli-plugins", "examples", "app") var CreateCmd = &cobra.Command{ - Use: "create", - Short: "Create Command ", - Long: `This command helps you to work flogo contributions `, - PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Use: "create", + Short: "Create Command ", + Long: `This command helps you to work flogo contributions `, Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { appName = args[0] @@ -39,12 +36,6 @@ var CreateCmd = &cobra.Command{ if !strings.HasPrefix(appName, "http") { //Install the example dir in GOPATH/src - err := util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) - if err != nil { - fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) - os.Exit(1) - } - flogoJsonPath = filepath.Join(goPath, "src", examplePath, appName+".json") if _, err := os.Stat(flogoJsonPath); os.IsNotExist(err) { diff --git a/examples/commands/list.go b/examples/commands/list.go index 5a06c2a..00540d5 100644 --- a/examples/commands/list.go +++ b/examples/commands/list.go @@ -3,40 +3,25 @@ package commands import ( "fmt" "os" - "os/exec" "path/filepath" "text/tabwriter" - "github.com/project-flogo/cli/util" "github.com/spf13/cobra" ) var ListAppCmd = &cobra.Command{ - Use: "list", - Short: "List Contributions Command ", - Long: `This command helps you to find flogo contributions `, - PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Use: "list", + Short: "List Contributions Command ", + Long: `This command helps you to find flogo contributions `, Run: func(cmd *cobra.Command, args []string) { - currentDir, err := os.Getwd() - if err != nil { - fmt.Fprintf(os.Stderr, "Error determining working directory: %v\n", err) - os.Exit(1) - } - - err = util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) - if err != nil { - fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) - os.Exit(1) - } - var result []string if _, err := os.Stat(filepath.Join(goPath, "src", examplePath)); os.IsNotExist(err) { fmt.Fprintf(os.Stderr, "Error listing examples directory %v", err) os.Exit(1) } - err = filepath.Walk(filepath.Join(goPath, "src", examplePath), func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(filepath.Join(goPath, "src", examplePath), func(path string, info os.FileInfo, err error) error { if !info.IsDir() { result = append(result, info.Name()) } diff --git a/examples/examples.go b/examples/examples.go index d4f0eb2..9b33284 100644 --- a/examples/examples.go +++ b/examples/examples.go @@ -1,17 +1,40 @@ package examples import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "github.com/project-flogo/cli-plugins/examples/commands" "github.com/project-flogo/cli/common" + "github.com/project-flogo/cli/util" "github.com/spf13/cobra" ) var exmpCmd = &cobra.Command{ - Use: "example", - Short: "Developer tool for basic work ", - Long: `This command helps you to work flogo contributions `, - PersistentPreRun: func(cmd *cobra.Command, args []string) {}, + Use: "example", + Short: "Developer tool for basic work ", + Long: `This command helps you to work flogo contributions `, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + + if _, err := os.Stat(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "project-flogo", "cli-plugins", "examples")); os.IsNotExist(err) { + + currentDir, err := os.Getwd() + if err != nil { + fmt.Fprintf(os.Stderr, "Error determining working directory: %v\n", err) + os.Exit(1) + } + + err = util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) + if err != nil { + fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) + os.Exit(1) + } + } + + }, Run: func(cmd *cobra.Command, args []string) { }, } From eef8d3e9ad6a8e2a15288e5106f01e32476746d5 Mon Sep 17 00:00:00 2001 From: skothari-tibco Date: Mon, 9 Sep 2019 13:06:14 -0400 Subject: [PATCH 3/3] Edit path --- examples/app/rest.json | 71 ------------------------------------- examples/commands/create.go | 2 +- examples/examples.go | 4 +-- 3 files changed, 3 insertions(+), 74 deletions(-) delete mode 100644 examples/app/rest.json diff --git a/examples/app/rest.json b/examples/app/rest.json deleted file mode 100644 index 078962b..0000000 --- a/examples/app/rest.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "RestApp", - "type": "flogo:app", - "version": "0.0.1", - "description": "My flogo application description", - "appModel": "1.1.0", - "imports": [ - "github.com/project-flogo/contrib@latest:/activity/log", - "github.com/project-flogo/contrib@latest:/trigger/rest", - "github.com/project-flogo/flow@latest" - ], - "triggers": [ - { - "id": "my_rest_trigger", - "ref": "#rest", - "settings": { - "port": "8888" - }, - "handlers": [ - { - "settings": { - "method": "GET", - "path": "/test/:val" - }, - "actions": [ - { - "ref": "#flow", - "settings": { - "flowURI": "res://flow:simple_flow" - }, - "input": { - "in": "=$.pathParams.val" - } - } - ] - } - ] - } - ], - "resources": [ - { - "id": "flow:simple_flow", - "data": { - "name": "simple_flow", - "metadata": { - "input": [ - { "name": "in", "type": "string", "value": "test" } - ], - "output": [ - { "name": "out", "type": "string" } - ] - }, - "tasks": [ - { - "id": "log", - "name": "Log Message", - "activity": { - "ref": "#log", - "input": { - "message": "=$flow.in", - "flowInfo": "false", - "addToFlow": "false" - } - } - } - ], - "links": [] - } - } - ] - } \ No newline at end of file diff --git a/examples/commands/create.go b/examples/commands/create.go index 89daae3..1feaec9 100644 --- a/examples/commands/create.go +++ b/examples/commands/create.go @@ -13,7 +13,7 @@ import ( var appName string var flogoJsonPath string var goPath = os.Getenv("GOPATH") -var examplePath = filepath.Join("github.com", "project-flogo", "cli-plugins", "examples", "app") +var examplePath = filepath.Join("github.com", "project-flogo", "examples") var CreateCmd = &cobra.Command{ Use: "create", diff --git a/examples/examples.go b/examples/examples.go index 9b33284..2b8f772 100644 --- a/examples/examples.go +++ b/examples/examples.go @@ -19,7 +19,7 @@ var exmpCmd = &cobra.Command{ Long: `This command helps you to work flogo contributions `, PersistentPreRun: func(cmd *cobra.Command, args []string) { - if _, err := os.Stat(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "project-flogo", "cli-plugins", "examples")); os.IsNotExist(err) { + if _, err := os.Stat(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "project-flogo", "examples")); os.IsNotExist(err) { currentDir, err := os.Getwd() if err != nil { @@ -27,7 +27,7 @@ var exmpCmd = &cobra.Command{ os.Exit(1) } - err = util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/cli-plugins/examples"), currentDir) + err = util.ExecCmd(exec.Command("go", "get", "github.com/project-flogo/examples"), currentDir) if err != nil { fmt.Fprintf(os.Stderr, "Error installing examples directory %v", err) os.Exit(1)