diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000..da07aa6 Binary files /dev/null and b/examples/.DS_Store differ diff --git a/examples/commands/create.go b/examples/commands/create.go new file mode 100644 index 0000000..1feaec9 --- /dev/null +++ b/examples/commands/create.go @@ -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) + } + }, +} diff --git a/examples/commands/list.go b/examples/commands/list.go new file mode 100644 index 0000000..00540d5 --- /dev/null +++ b/examples/commands/list.go @@ -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() + }, +} diff --git a/examples/examples.go b/examples/examples.go new file mode 100644 index 0000000..2b8f772 --- /dev/null +++ b/examples/examples.go @@ -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) + +} 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=