Skip to content

Commit

Permalink
Refactor repo and starterkit code
Browse files Browse the repository at this point in the history
  • Loading branch information
WSMathias committed Apr 1, 2020
1 parent 73f4ec7 commit a62e6cf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
11 changes: 5 additions & 6 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
)

type createCmd struct {
out io.Writer
starterkit string
home vega.Home
dest string
repositoryName string
repo string
out io.Writer
starterkit string
home vega.Home
dest string
repo string
}

func newCreateCmd(out io.Writer) *cobra.Command {
Expand Down
12 changes: 6 additions & 6 deletions cmd/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import (
vega "github.com/srijanone/vega/pkg/core"
)

type RepositoryListCmd struct {
type repositoryListCmd struct {
out io.Writer
home vega.Home
}

func newRepositoryList(out io.Writer) *cobra.Command {
const listCmdDesc = "list all the starterkit repositories available locally"
repositoryListCmd := RepositoryListCmd{
repoListCmd := repositoryListCmd{
out: out,
}
listCmd := &cobra.Command{
Use: "list",
Short: listCmdDesc,
Long: listCmdDesc,
Run: func(cmd *cobra.Command, args []string) {
repositoryListCmd.execute()
repoListCmd.execute()
},
}

repositoryListCmd.home = vega.Home(homePath())
repoListCmd.home = vega.Home(homePath())

return listCmd
}

func (cmd *RepositoryListCmd) execute() error {
repositories, err := vega.Repositories(cmd.home.StarterKits())
func (cmd *repositoryListCmd) execute() error {
repositories, err := vega.RepoList(cmd.home.StarterKits())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/starterkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DockerfileName string = "Dockerfile"

func (sk *StarterKit) Create(dest string) error {
// TODO: Merge gracefully in future
fmt.Printf("Creating strterkit %s ... \n", sk.Name)
fmt.Printf("Creating starterkit %s ... \n", sk.Name)
err := copy.Copy(sk.Path, dest)
return err
}
20 changes: 17 additions & 3 deletions pkg/core/starterkit_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type StarterKitRepo struct {
Dir string // starterkit directory name at source/remote
}

// Repositories list of all the local Repositories
func Repositories(path string) ([]StarterKitRepo, error) {
// RepoList list of all the local Repositories
func RepoList(path string) ([]StarterKitRepo, error) {

var repositories []StarterKitRepo
files, err := ioutil.ReadDir(path)
Expand Down Expand Up @@ -94,7 +94,21 @@ func (repo *StarterKitRepo) Find(name string) ([]StarterKit, error) {
}

//Add add staterkits repo to vega and download all the starterkits
func (repo StarterKitRepo) Add() {
func (repo *StarterKitRepo) Add() {
d := downloader.Downloader{}
if repo.Dir == "" {
repo.Dir = "starterkits"
}
sourceRepo := fmt.Sprintf("%s//%s", repo.URL, repo.Dir)
fmt.Println("Downloading starterkits...")
if repo.Path == "" {
repo.Path = filepath.Join(repo.Home.StarterKits(), repo.Name)
}
d.Download(sourceRepo, repo.Path)
}

//Delete starterkit repo
func (repo StarterKitRepo) Delete() {
d := downloader.Downloader{}
if repo.Dir == "" {
repo.Dir = "starterkits"
Expand Down

0 comments on commit a62e6cf

Please sign in to comment.