Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #25 from ZupIT/feature/auto_download
Browse files Browse the repository at this point in the history
Feature/auto_download
  • Loading branch information
viniciusramosdefaria authored Feb 21, 2020
2 parents 8d65e47 + 0d22555 commit faecc08
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 480 deletions.
6 changes: 2 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ZupIT/ritchie-cli/pkg/env"
"github.com/ZupIT/ritchie-cli/pkg/env/envcredential"
"github.com/ZupIT/ritchie-cli/pkg/formula"
"github.com/ZupIT/ritchie-cli/pkg/git"
"github.com/ZupIT/ritchie-cli/pkg/login"
"github.com/ZupIT/ritchie-cli/pkg/metrics"
"github.com/ZupIT/ritchie-cli/pkg/tree"
Expand All @@ -42,20 +41,19 @@ func main() {
ritchieHomePath := fmt.Sprintf(ritchieHomePattern, usr.HomeDir)

// deps
gitManager := git.NewDefaultManager()
sessionManager := session.NewDefaultManager(ritchieHomePath)
treeManager := tree.NewDefaultManager(ritchieHomePath, env.ServerUrl, http.DefaultClient, sessionManager)
loginManager := login.NewDefaultManager(ritchieHomePath, env.ServerUrl, http.DefaultClient, sessionManager, treeManager)
credManager := credential.NewDefaultManager(env.ServerUrl, http.DefaultClient, sessionManager)
userManager := ruser.NewDefaultManager(env.ServerUrl, http.DefaultClient, sessionManager)
workspaceManager := workspace.NewDefaultManager(ritchieHomePath, env.ServerUrl, http.DefaultClient, treeManager, gitManager, credManager, sessionManager)
workspaceManager := workspace.NewDefaultManager(ritchieHomePath, treeManager)
autocompleteManager := autocomplete.NewDefaultManager(env.ServerUrl, ritchieHomePath, http.DefaultClient)
ctxManager := context.NewDefaultManager(sessionManager)
metricsManager := metrics.NewDefaultManager(env.ServerUrl, &http.Client{Timeout: 2 * time.Second}, sessionManager)
credResolver := envcredential.NewResolver(credManager)
envResolvers := make(env.Resolvers)
envResolvers[env.Credential] = credResolver
formulaManager := formula.NewDefaultManager(ritchieHomePath, envResolvers)
formulaManager := formula.NewDefaultManager(ritchieHomePath, envResolvers, http.DefaultClient)

// cmd tree
treeBuilder := cmd.NewTreeBuilder(treeManager, workspaceManager, credManager, formulaManager, loginManager, userManager, autocompleteManager, ctxManager)
Expand Down
29 changes: 0 additions & 29 deletions pkg/cmd/init.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type loginCmd struct {
}

// NewLoginCmd creates new cmd instance
func NewLoginCmd(loginManager login.Manager) *cobra.Command {
o := &loginCmd{loginManager}
func NewLoginCmd(l login.Manager) *cobra.Command {
o := &loginCmd{l}
return &cobra.Command{
Use: "login",
Short: "User login",
Expand All @@ -32,9 +32,9 @@ func (o *loginCmd) prompt() error {
if err != nil {
return err
}

log.Println("Starting login...")
err = o.loginManager.Authenticate(org, Version)
if err != nil {
if err := o.loginManager.Authenticate(org, Version); err != nil {
return err
}
return nil
Expand Down
25 changes: 15 additions & 10 deletions pkg/cmd/treebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

var (
coreCmds = []string{
"root_init", "root_set", "root_set_credential", "root_set_context",
"root_create", "root_create_user", "root_delete", "root_delete_user",
"root_delete_context", "root_show", "root_show_context", "root_help",
"root_login", "root_completion", "root_completion_zsh", "root_completion_bash"}
"root_set", "root_set_credential", "root_set_context", "root_create",
"root_create_user", "root_delete", "root_delete_user", "root_delete_context",
"root_show", "root_show_context", "root_help", "root_login", "root_completion",
"root_completion_zsh", "root_completion_bash"}
)

// treeBuilder type that represents the tree builder
Expand Down Expand Up @@ -64,7 +64,6 @@ func NewTreeBuilder(
// BuildTree builds the tree of the commands
func (b *treeBuilder) BuildTree() (*cobra.Command, error) {
rootCmd := NewRootCmd(b.workspaceManager)
initCmd := NewInitCmd(b.workspaceManager)
setCmd := NewSetCmd()
showCmd := NewShowCmd()
createCmd := NewCreateCmd()
Expand All @@ -88,7 +87,7 @@ func (b *treeBuilder) BuildTree() (*cobra.Command, error) {
deleteCmd.AddCommand(deleteCtxCmd)
showCmd.AddCommand(showCtxCmd)

rootCmd.AddCommand(initCmd, setCmd, createCmd, deleteCmd, loginCmd, autocompleteCmd, showCmd)
rootCmd.AddCommand(setCmd, createCmd, deleteCmd, loginCmd, autocompleteCmd, showCmd)

treeCmd, err := b.treeManager.GetLocalTree()
if err != nil {
Expand Down Expand Up @@ -116,6 +115,7 @@ func (b *treeBuilder) processTree(treeCmd *tree.Representation, rootCmd *cobra.C
annotations["formulaPath"] = f.Path
annotations["formulaBin"] = f.Bin
annotations["formulaConfig"] = f.Config
annotations["formulaRepoUrl"] = f.RepoUrl
cmd = &cobra.Command{
Use: v.Usage,
Short: v.Help,
Expand All @@ -126,12 +126,17 @@ func (b *treeBuilder) processTree(treeCmd *tree.Representation, rootCmd *cobra.C
fPath := cmd.Annotations["formulaPath"]
fBin := cmd.Annotations["formulaBin"]
fConf := cmd.Annotations["formulaConfig"]
fRepoUrl := cmd.Annotations["formulaRepoUrl"]
frm := formula.Definition{
Path: fPath,
Bin: fBin,
Config: fConf,
Path: fPath,
Bin: fBin,
Config: fConf,
RepoUrl: fRepoUrl,
}
err := b.formulaManager.Run(frm)
if err != nil {
return err
}
b.formulaManager.Run(frm)
}
return nil
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/treebuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ func TestBuildTree(t *testing.T) {
CheckWorkingDirFunc: func() error {
return nil
},
InitWorkingDirFunc: func() error {
return nil
},
}

credman := &credential.ManagerMock{
Expand All @@ -46,7 +43,7 @@ func TestBuildTree(t *testing.T) {
}

logman := &login.ManagerMock{
AuthenticateFunc: func(organization,version string) error {
AuthenticateFunc: func(organization, version string) error {
return nil
},
}
Expand Down
Loading

0 comments on commit faecc08

Please sign in to comment.