Skip to content

Commit

Permalink
Resolve Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
sparshadotel committed Aug 29, 2019
2 parents f810f65 + 71d41f1 commit b9e2b7e
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 18 deletions.
10 changes: 9 additions & 1 deletion cli/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"os"

"github.com/urfave/cli"
Expand Down Expand Up @@ -32,6 +31,15 @@ func Initialize(info *Info) error {
fmt.Println("Shift Shift shift")
},
},
cli.Command{
Name: "setup",
Action: func(ctx *cli.Context) error {
Setup()

return nil
},
},
}

return app.Run(os.Args)
}
10 changes: 10 additions & 0 deletions cli/cmd/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cmd

import (
"github.com/leapfrogtechnology/shift/cli/internal/setup"
)

// Setup prompts user for required information for creating a project.
func Setup() {
setup.Run()
}
6 changes: 4 additions & 2 deletions cli/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/lftechnology/shift/cli
module github.com/leapfrogtechnology/shift/cli

go 1.12

require (
github.com/pratishshr/envault v1.1.1
github.com/AlecAivazis/survey/v2 v2.0.4
github.com/briandowns/spinner v1.6.1
github.com/go-resty/resty/v2 v2.0.0
github.com/urfave/cli v1.21.0
)
27 changes: 15 additions & 12 deletions cli/go.sum
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
github.com/AlecAivazis/survey/v2 v2.0.1 h1:fQuEpIq5H/rJMaGqiOtPBgnRZP1oexFYRi6bonYTi0w=
github.com/AlecAivazis/survey/v2 v2.0.1/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/AlecAivazis/survey/v2 v2.0.4 h1:qzXnJSzXEvmUllWqMBWpZndvT2YfoAUzAMvZUax3L2M=
github.com/AlecAivazis/survey/v2 v2.0.4/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/aws/aws-sdk-go v1.20.3 h1:iQLxGfR0yh7g5M8Xg7wOGyhQ4hoZb/zA0XQNOGPdlpY=
github.com/aws/aws-sdk-go v1.20.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/briandowns/spinner v1.6.1 h1:LBxHu5WLyVuVEtTD72xegiC7QJGx598LBpo3ywKTapA=
github.com/briandowns/spinner v1.6.1/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-resty/resty/v2 v2.0.0 h1:9Nq/U+V4xsoDnDa/iTrABDWUCuk3Ne92XFHPe6dKWUc=
github.com/go-resty/resty/v2 v2.0.0/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pratishshr/envault v1.1.1 h1:hBsSaeibwuNRuKFSlij9uXOQum31XU9bvC2qhHuwnwU=
github.com/pratishshr/envault v1.1.1/go.mod h1:KS8t43iMny1YOY01Zn9FOOovh0/M6b32apu/eMbM8hY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE=
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
199 changes: 199 additions & 0 deletions cli/internal/setup/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package setup

import (
"fmt"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/leapfrogtechnology/shift/cli/utils/github"
"github.com/leapfrogtechnology/shift/cli/utils/spinner"
)

type projectDetails struct {
ProjectName string
}

type deploymentDetails struct {
DeploymentName string
CloudProvider string
AccessKey string
SecretKey string
DeploymentType string
GitProvider string
}

func askProjectDetails() *projectDetails {
questions := []*survey.Question{
{
Name: "projectName",
Prompt: &survey.Input{
Message: "Project Name",
},
},
}

answers := &projectDetails{}
err := survey.Ask(questions, answers)

if err != nil {
fmt.Println(err)
}

return answers
}

func askDeploymentDetails() *deploymentDetails {
questions := []*survey.Question{
{
Name: "deploymentName",
Prompt: &survey.Input{
Message: "Deployment Name:",
},
},
{
Name: "cloudProvider",
Prompt: &survey.Select{
Message: "Choose Cloud Provider:",
Options: []string{"AWS", "Azure", "GCP"},
},
},
{
Name: "accessKey",
Prompt: &survey.Input{
Message: "Access Key:",
},
},
{
Name: "secretKey",
Prompt: &survey.Input{
Message: "Secret Key:",
},
},
{
Name: "deploymentType",
Prompt: &survey.Select{
Message: "Choose Deployment Type:",
Options: []string{"Frontend", "Backend"},
},
},
{
Name: "gitProvider",
Prompt: &survey.Select{
Message: "Choose Git Provider",
Options: []string{"Github", "Gitlab", "BitBucket"},
},
},
}

answers := &deploymentDetails{}
err := survey.Ask(questions, answers)

if err != nil {
fmt.Println(err)
}

return answers
}

func askGitCredentials(gitProvider string) *github.GitCredentials {
fmt.Println("\n Connect " + gitProvider)
questions := []*survey.Question{
{
Name: "username",
Prompt: &survey.Input{
Message: "Username",
},
},
{
Name: "password",
Prompt: &survey.Password{
Message: "Password",
},
},
}

answers := &github.GitCredentials{}
err := survey.Ask(questions, answers)

if err != nil {
fmt.Println(err)
}

return answers
}

func chooseOrganization(personalToken string) string {
spinner.Start()
user, _ := github.FetchUser(personalToken)
organizations, _ := github.FetchOrganizations(personalToken)
spinner.Stop()

questions := &survey.Select{
Message: "Choose user/organization:",
Options: append(organizations, user+" (User)"),
}

org := ""
err := survey.AskOne(questions, &org)

if err != nil {
fmt.Println(err)
}

return org
}

func chooseRepo(personalToken string, organization string) string {
repos := []string{}

spinner.Start()
if strings.Contains(organization, "(User)") {
repos, _ = github.FetchUserRepos(personalToken)
} else {
repos, _ = github.FetchOrgRepos(personalToken, organization)
}
spinner.Stop()

questions := &survey.Select{
Message: "Choose Repository:",
Options: repos,
}

org := ""
err := survey.AskOne(questions, &org)

if err != nil {
fmt.Println(err)
}

return org
}

// Run initializes setup for shift projects.
func Run() {
projectDetails := askProjectDetails()
deploymentDetails := askDeploymentDetails()
gitCredentials := askGitCredentials(deploymentDetails.GitProvider)

spinner.Start()
personalToken, _ := github.CreatePersonalToken(gitCredentials)
spinner.Stop()

organization := chooseOrganization(personalToken)
repo := chooseRepo(personalToken, organization)

fmt.Print("ProjectDetails: ")
fmt.Println(projectDetails)

fmt.Print("DeploymentDetails: ")
fmt.Println(deploymentDetails)

fmt.Print("Access Token: ")
fmt.Println(personalToken)

fmt.Print("Organization: ")
fmt.Println(organization)

fmt.Print("Repository: ")
fmt.Println(repo)
}
5 changes: 3 additions & 2 deletions cli/shift.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cli
package main

import (
"fmt"

"github.com/leapfrogtechnology/shift/cli/cmd"
)

func Initialize() {
// Initialize Cli
func main() {
info := &cmd.Info{
Name: "Shift",
Version: "0.0.1",
Expand Down
Loading

0 comments on commit b9e2b7e

Please sign in to comment.