Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example list create #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/.DS_Store
Binary file not shown.
53 changes: 53 additions & 0 deletions examples/commands/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package commands

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/project-flogo/cli/api"
"github.com/spf13/cobra"
)

var appName string
var flogoJsonPath string
var goPath = os.Getenv("GOPATH")
var examplePath = filepath.Join("github.com", "project-flogo", "examples")

var CreateCmd = &cobra.Command{
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]
} 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

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)
}
},
}
49 changes: 49 additions & 0 deletions examples/commands/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package commands

import (
"fmt"
"os"
"path/filepath"

"text/tabwriter"

"github.com/spf13/cobra"
)

var ListAppCmd = &cobra.Command{
Use: "list",
Short: "List Contributions Command ",
Long: `This command helps you to find flogo contributions `,
Run: func(cmd *cobra.Command, args []string) {

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()
},
}
47 changes: 47 additions & 0 deletions examples/examples.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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) {

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 {
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/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) {
},
}

func init() {
exmpCmd.AddCommand(commands.CreateCmd)
exmpCmd.AddCommand(commands.ListAppCmd)
common.RegisterPlugin(exmpCmd)

}
9 changes: 9 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
24 changes: 24 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -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=