Skip to content

Commit

Permalink
Merge pull request #1449 from merico-dev/mvp
Browse files Browse the repository at this point in the history
feat: new commands support: start/create
  • Loading branch information
daniel-hutao authored Feb 1, 2023
2 parents e95ebc7 + 5085194 commit e178b4d
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cmd/devstream/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"log"

"github.com/spf13/cobra"

"github.com/devstream-io/devstream/internal/pkg/create"
)

var createCMD = &cobra.Command{
Use: "create",
Short: "create",
Long: `create.`,
Run: createCMDFunc,
}

func createCMDFunc(cmd *cobra.Command, args []string) {
err := create.Create()
if err != nil {
log.Panic(err)
}
}
3 changes: 3 additions & 0 deletions cmd/devstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func init() {
rootCMD.AddCommand(listCMD)
rootCMD.AddCommand(showCMD)
rootCMD.AddCommand(upgradeCMD)

rootCMD.AddCommand(startCMD)
rootCMD.AddCommand(createCMD)
}

func initConfig() {
Expand Down
22 changes: 22 additions & 0 deletions cmd/devstream/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/spf13/cobra"

"github.com/devstream-io/devstream/internal/pkg/start"
"github.com/devstream-io/devstream/pkg/util/log"
)

var startCMD = &cobra.Command{
Use: "start",
Short: "start",
Long: `start.`,
Run: startCMDFunc,
}

func startCMDFunc(_ *cobra.Command, _ []string) {
err := start.Start()
if err != nil {
log.Fatal(err)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-getter v1.6.2
github.com/imdario/mergo v0.3.12
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/mapstructure v1.5.0
github.com/mittwald/go-helm-client v0.8.4
github.com/onsi/ginkgo/v2 v2.1.4
Expand Down Expand Up @@ -83,6 +84,7 @@ require (
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/containerd/containerd v1.5.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -171,7 +173,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
Expand Down Expand Up @@ -223,7 +224,6 @@ require (
gopkg.in/gorp.v1 v1.7.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.22.4 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d8
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cilium/ebpf v0.0.0-20200110133405-4032b1d8aae3/go.mod h1:MA5e5Lr8slmEg9bt0VpxxWqJlO4iwu3FBdHUzV7wQVg=
github.com/cilium/ebpf v0.0.0-20200702112145-1c8d4c9ef775/go.mod h1:7cR51M8ViRLIdUjrmSXlK9pkrsDlLHbO8jiB8X8JnOc=
Expand Down Expand Up @@ -940,6 +943,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/malexdev/utfutil v0.0.0-20180510171754-00c8d4a8e7a8/go.mod h1:UtpLyb/EupVKXF/N0b4NRe1DNg+QYJsnsHQ038romhM=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY=
Expand Down
41 changes: 41 additions & 0 deletions internal/pkg/create/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package create

import (
"fmt"
"time"
)

func Create() error {
helloMsg := func() {
fmt.Println("I'll scaffold a new repository for you.")
time.Sleep(time.Second)
fmt.Println("Are you ready?")
time.Sleep(time.Second)
fmt.Println("Let's get started.")
time.Sleep(time.Second)
}
helloMsg()

lang, err := getLanguage()
if err != nil {
return err
}

time.Sleep(time.Second)
fmt.Println("\nPlease choose a framework next.")
time.Sleep(time.Second)

fram, err := getFramework()
if err != nil {
return err
}

return createRepo(lang, fram)
// TODO(daniel-hutao): cicd
}

// TODO(daniel-hutao): support python/flask first
func createRepo(lang, fram string) error {
fmt.Printf("Lang: %s, Fram: %s\n", lang, fram)
return nil
}
56 changes: 56 additions & 0 deletions internal/pkg/create/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package create

import (
"fmt"
"strings"

"github.com/manifoldco/promptui"
)

type framework struct {
Name string
}

//TODO(daniel-hutao): support Python first
func getFramework() (string, error) {
frameworks := []framework{
{Name: "flask"},
{Name: "django"},
}

templates := &promptui.SelectTemplates{
Label: "{{ . }}?",
Active: "\U0001F336 {{ .Name | cyan }}",
Inactive: " {{ .Name | cyan }}",
Selected: "\U0001F336 {{ .Name | red | cyan }}",
Details: `
--------- Framework ----------
{{ "Name:" | faint }} {{ .Name }}`,
}

searcher := func(input string, index int) bool {
pepper := frameworks[index]
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)

return strings.Contains(name, input)
}

prompt := promptui.Select{
Label: "Choose your framework",
Items: frameworks,
Templates: templates,
Size: 4,
Searcher: searcher,
}

i, _, err := prompt.Run()

if err != nil {
return "", fmt.Errorf("got unsupported framework")
}

retFram := frameworks[i].Name
fmt.Printf("You choosed: %s.\n", retFram)
return retFram, nil
}
58 changes: 58 additions & 0 deletions internal/pkg/create/language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package create

import (
"fmt"
"strings"

"github.com/manifoldco/promptui"
)

type language struct {
Name string
}

func getLanguage() (string, error) {
languages := []language{
{Name: "Python"},
{Name: "Java"},
{Name: "Go"},
{Name: "Node.js"},
{Name: "C++"},
}

templates := &promptui.SelectTemplates{
Label: "{{ . }}?",
Active: "\U0001F336 {{ .Name | cyan }}",
Inactive: " {{ .Name | cyan }}",
Selected: "\U0001F336 {{ .Name | red | cyan }}",
Details: `
--------- Language ----------
{{ "Name:" | faint }} {{ .Name }}`,
}

searcher := func(input string, index int) bool {
pepper := languages[index]
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)

return strings.Contains(name, input)
}

prompt := promptui.Select{
Label: "Choose your language",
Items: languages,
Templates: templates,
Size: 4,
Searcher: searcher,
}

i, _, err := prompt.Run()

if err != nil {
return "", fmt.Errorf("got unsupported language")
}

retLang := languages[i].Name
fmt.Printf("You choosed: %s.\n", retLang)
return retLang, nil
}
Loading

0 comments on commit e178b4d

Please sign in to comment.