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 #282 from kaduartur/feature/remove_single_names
Browse files Browse the repository at this point in the history
Feature/remove_single_names
  • Loading branch information
victor-schumacher authored Jul 14, 2020
2 parents 9b78166 + 20bd9d6 commit be11a5b
Show file tree
Hide file tree
Showing 226 changed files with 19,812 additions and 963 deletions.
3 changes: 1 addition & 2 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
go build -o ./dist/windows/team/rit.exe -v ./cmd/team/main.go
go build -o ./dist/windows/single/rit.exe -v ./cmd/single/main.go
go build -o ./dist/windows/rit.exe -v ./cmd/main.go
10 changes: 4 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
fworkspace "github.com/ZupIT/ritchie-cli/pkg/formula/workspace"
"github.com/ZupIT/ritchie-cli/pkg/prompt"
"github.com/ZupIT/ritchie-cli/pkg/rcontext"
"github.com/ZupIT/ritchie-cli/pkg/session"
"github.com/ZupIT/ritchie-cli/pkg/stream"
)

Expand Down Expand Up @@ -74,14 +73,13 @@ func buildCommands() *cobra.Command {
repoDeleter := repo.NewDeleter(ritchieHomeDir, fileManager, dirManager)
repoPrioritySetter := repo.NewPrioritySetter(ritchieHomeDir, fileManager, dirManager)

sessionManager := session.NewManager(ritchieHomeDir)
ctxFinder := rcontext.NewFinder(ritchieHomeDir)
ctxSetter := rcontext.NewSetter(ritchieHomeDir, ctxFinder)
ctxRemover := rcontext.NewRemover(ritchieHomeDir, ctxFinder)
ctxFindSetter := rcontext.NewFindSetter(ritchieHomeDir, ctxFinder, ctxSetter)
ctxFindRemover := rcontext.NewFindRemover(ritchieHomeDir, ctxFinder, ctxRemover)
credSetter := credsingle.NewSetter(ritchieHomeDir, ctxFinder, sessionManager)
credFinder := credsingle.NewFinder(ritchieHomeDir, ctxFinder, sessionManager)
credSetter := credsingle.NewSetter(ritchieHomeDir, ctxFinder)
credFinder := credsingle.NewFinder(ritchieHomeDir, ctxFinder)
treeManager := tree.NewTreeManager(ritchieHomeDir, repoLister, api.CoreCmds)
credSettings := credsingle.NewSingleSettings(fileManager)
autocompleteGen := autocomplete.NewGenerator(treeManager)
Expand All @@ -90,7 +88,7 @@ func buildCommands() *cobra.Command {
envResolvers[env.Credential] = credResolver

inputManager := runner.NewInputManager(envResolvers, inputList, inputText, inputBool, inputPassword)
formulaSetup := runner.NewDefaultSingleSetup(ritchieHomeDir, http.DefaultClient)
formulaSetup := runner.NewDefaultSetup(ritchieHomeDir)

defaultPreRunner := runner.NewDefaultPreRunner(formulaSetup)
dockerPreRunner := runner.NewDockerPreRunner(formulaSetup)
Expand Down Expand Up @@ -129,7 +127,7 @@ func buildCommands() *cobra.Command {
upgradeCmd := cmd.NewUpgradeCmd(defaultUpgradeResolver, upgradeManager, defaultUrlFinder)

// level 2
setCredentialCmd := cmd.NewSingleSetCredentialCmd(
setCredentialCmd := cmd.NewSetCredentialCmd(
credSetter,
credSettings,
inputText,
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ go 1.14
require (
github.com/AlecAivazis/survey/v2 v2.0.7
github.com/denisbrodbeck/machineid v1.0.1
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/google/uuid v1.1.1
github.com/gookit/color v1.2.5
github.com/gorilla/mux v1.7.4 // indirect
github.com/gosuri/uitable v0.0.4
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/kaduartur/go-cli-spinner v1.0.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-shellwords v1.0.10 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.0
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pkg/errors v0.9.1
github.com/radovskyb/watcher v1.0.7
github.com/spf13/cobra v1.0.0
Expand Down
1 change: 0 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

const (
ritchieHomePattern = "%s/.rit"
// CoreCmdsDesc commands group description
CoreCmdsDesc = "core commands:"
)

Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/add_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
ErrCommonsRepoName = errors.New("the name \"commons\" is not valid for the repository name, try to enter another name")
)

type AddRepoCmd struct {
type addRepoCmd struct {
client *http.Client
repo formula.RepositoryAddLister
github github.Repositories
Expand All @@ -41,7 +41,7 @@ func NewAddRepoCmd(
inBool prompt.InputBool,
inInt prompt.InputInt,
) *cobra.Command {
addRepo := AddRepoCmd{
addRepo := addRepoCmd{
repo: repo,
github: github,
InputTextValidator: inText,
Expand All @@ -62,7 +62,7 @@ func NewAddRepoCmd(
return cmd
}

func (ad AddRepoCmd) runPrompt() CommandRunnerFunc {
func (ad addRepoCmd) runPrompt() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
name, err := ad.Text("Repository name: ", ad.repoNameValidator)
if err != nil {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (ad AddRepoCmd) runPrompt() CommandRunnerFunc {
}
}

func (ad AddRepoCmd) runStdin() CommandRunnerFunc {
func (ad addRepoCmd) runStdin() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {

r := formula.Repo{}
Expand All @@ -164,7 +164,7 @@ func (ad AddRepoCmd) runStdin() CommandRunnerFunc {
}
}

func (ad AddRepoCmd) repoNameValidator(text interface{}) error {
func (ad addRepoCmd) repoNameValidator(text interface{}) error {
in := text.(string)
if in == "" {
return ErrRepoNameNotEmpty
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/delete_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const (
deleteSuccessMsg = "Repository %q was deleted with success"
)

type DeleteRepoCmd struct {
type deleteRepoCmd struct {
formula.RepositoryLister
prompt.InputList
formula.RepositoryDeleter
}

func NewDeleteRepoCmd(rl formula.RepositoryLister, il prompt.InputList, rd formula.RepositoryDeleter) *cobra.Command {
dr := DeleteRepoCmd{rl, il, rd}
dr := deleteRepoCmd{rl, il, rd}
cmd := &cobra.Command{
Use: "repo",
Short: "Delete a repository",
Expand All @@ -30,7 +30,7 @@ func NewDeleteRepoCmd(rl formula.RepositoryLister, il prompt.InputList, rd formu
return cmd
}

func (dr DeleteRepoCmd) runFunc() CommandRunnerFunc {
func (dr deleteRepoCmd) runFunc() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
repos, err := dr.RepositoryLister.List()
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/formulas.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
)

const (
subCommand = " SUBCOMMAND"
Group = "group"
dockerFlag = "docker"
rootCmd = "root"
subCommand = " SUBCOMMAND"
Group = "group"
dockerFlag = "docker"
rootCmdName = "root"
)

type FormulaCommand struct {
Expand All @@ -43,7 +43,7 @@ func NewFormulaCommand(
func (f FormulaCommand) Add(root *cobra.Command) error {
treeRep := f.treeManager.MergedTree(false)
commands := make(map[string]*cobra.Command)
commands[rootCmd] = root
commands[rootCmdName] = root

for _, cmd := range treeRep.Commands {
cmdPath := api.Command{Parent: cmd.Parent, Usage: cmd.Usage}
Expand All @@ -67,7 +67,7 @@ func (f FormulaCommand) Add(root *cobra.Command) error {

func newSubCmd(cmd api.Command) *cobra.Command {
var group string
if cmd.Parent == rootCmd {
if cmd.Parent == rootCmdName {
group = fmt.Sprintf("%s repo commands:", cmd.Repo)
}

Expand All @@ -90,7 +90,7 @@ func (f FormulaCommand) newFormulaCmd(cmd api.Command) *cobra.Command {

addFlags(formulaCmd)
path := strings.ReplaceAll(strings.Replace(cmd.Parent, "root", "", 1), "_", string(os.PathSeparator))
path = fmt.Sprintf("%s%s%s", path, string(os.PathSeparator), cmd.Usage)
path = fmt.Sprintf("%s%s%s", path, string(os.PathSeparator), cmd.Usage)
formulaCmd.RunE = f.execFormulaFunc(cmd.Repo, path)

return formulaCmd
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const UsageMsg = ` How to contribute new formulas to the Ritchie community?

var CommonsRepoURL = "https://github.com/kaduartur/ritchie-formulas"

type InitCmd struct {
type initCmd struct {
repo formula.RepositoryAdder
git github.Repositories
}

func NewInitCmd(repo formula.RepositoryAdder, git github.Repositories) *cobra.Command {
o := InitCmd{repo: repo, git: git}
o := initCmd{repo: repo, git: git}

cmd := &cobra.Command{
Use: "init",
Expand All @@ -42,7 +42,7 @@ func NewInitCmd(repo formula.RepositoryAdder, git github.Repositories) *cobra.Co
return cmd
}

func (in InitCmd) runPrompt() CommandRunnerFunc {
func (in initCmd) runPrompt() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
repo := formula.Repo{
Name: "commons",
Expand Down
17 changes: 2 additions & 15 deletions pkg/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"
"testing"

"github.com/docker/docker/api/server"

"github.com/ZupIT/ritchie-cli/pkg/formula"
"github.com/ZupIT/ritchie-cli/pkg/security/otp"

"github.com/ZupIT/ritchie-cli/pkg/prompt"
"github.com/ZupIT/ritchie-cli/pkg/security"
"github.com/ZupIT/ritchie-cli/pkg/server"
)

func TestNewSingleInitCmd(t *testing.T) {
Expand All @@ -32,10 +31,6 @@ func Test_initTeamCmd_runPrompt(t *testing.T) {
InputPassword prompt.InputPassword
InputURL prompt.InputURL
InputBool prompt.InputBool
FindSetter server.FindSetter
LoginManager security.LoginManager
Loader formula.RepoLoader
Resolver otp.Resolver
}
tests := []struct {
name string
Expand All @@ -49,10 +44,6 @@ func Test_initTeamCmd_runPrompt(t *testing.T) {
InputPassword: inputPasswordMock{},
InputURL: inputURLMock{},
InputBool: inputFalseMock{},
FindSetter: findSetterServerMock{},
LoginManager: loginManagerMock{},
Loader: repoLoaderMock{},
Resolver: otpResolverMock{},
},
wantErr: false,
},
Expand All @@ -63,10 +54,6 @@ func Test_initTeamCmd_runPrompt(t *testing.T) {
InputPassword: inputPasswordMock{},
InputURL: inputURLMock{},
InputBool: inputTrueMock{},
FindSetter: findSetterServerMock{},
LoginManager: loginManagerMock{},
Loader: repoLoaderMock{},
Resolver: otpResolverCustomMock{
requestOtp: func(url, organization string) (otp.Response, error) {
return otp.Response{}, errors.New("some error")
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/list_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const (
totalOneRepoMsg = "There is 1 repo"
)

type ListRepoCmd struct {
type listRepoCmd struct {
formula.RepositoryLister
}

func NewListRepoCmd(rl formula.RepositoryLister) *cobra.Command {
lr := ListRepoCmd{rl}
lr := listRepoCmd{rl}
cmd := &cobra.Command{
Use: "repo",
Short: "Show a list with all your available repositories",
Expand All @@ -30,7 +30,7 @@ func NewListRepoCmd(rl formula.RepositoryLister) *cobra.Command {
return cmd
}

func (lr ListRepoCmd) runFunc() CommandRunnerFunc {
func (lr listRepoCmd) runFunc() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
repos, err := lr.List()
if err != nil {
Expand Down
47 changes: 3 additions & 44 deletions pkg/cmd/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cmd
import (
"errors"

"github.com/docker/docker/api/server"
"github.com/spf13/cobra"

"github.com/ZupIT/ritchie-cli/pkg/api"
"github.com/ZupIT/ritchie-cli/pkg/autocomplete"
"github.com/ZupIT/ritchie-cli/pkg/credential"
"github.com/ZupIT/ritchie-cli/pkg/formula"
"github.com/ZupIT/ritchie-cli/pkg/rcontext"
"github.com/ZupIT/ritchie-cli/pkg/security"
"github.com/ZupIT/ritchie-cli/pkg/security/otp"
"github.com/ZupIT/ritchie-cli/pkg/server"
"github.com/spf13/cobra"
)

type inputTextMock struct{}
Expand Down Expand Up @@ -226,18 +225,6 @@ func (repoUpdaterMock) Update() error {
return nil
}

type loginManagerMock struct{}

func (loginManagerMock) Login(security.User) error {
return nil
}

type logoutManagerMock struct{}

func (logoutManagerMock) Logout() error {
return nil
}

type credSetterMock struct{}

func (credSetterMock) Set(d credential.Detail) error {
Expand Down Expand Up @@ -296,12 +283,6 @@ func (t treeMock) MergedTree(bool) formula.Tree {
return t.tree
}

type passphraseManagerMock struct{}

func (passphraseManagerMock) Save(security.Passphrase) error {
return nil
}

type findSetterServerMock struct{}

func (findSetterServerMock) Set(*server.Config) error {
Expand Down Expand Up @@ -346,14 +327,6 @@ func (m inputTextCustomMock) TextWithValidate(name string, validate func(interfa
return m.textWithValidate(name, validate)
}

type loginManagerCustomMock struct {
login func(security.User) error
}

func (m loginManagerCustomMock) Login(user security.User) error {
return m.login(user)
}

type inputURLCustomMock struct {
url func(name, defaultValue string) (string, error)
}
Expand All @@ -375,17 +348,3 @@ type InputMultilineMock struct{}
func (InputMultilineMock) MultiLineText(name string, required bool) (string, error) {
return "username=ritchie", nil
}

type otpResolverMock struct{}

func (m otpResolverMock) RequestOtp(url, organization string) (otp.Response, error) {
return otp.Response{Otp: true}, nil
}

type otpResolverCustomMock struct {
requestOtp func(url, organization string) (otp.Response, error)
}

func (m otpResolverCustomMock) RequestOtp(url, organization string) (otp.Response, error) {
return m.requestOtp(url, organization)
}
Loading

0 comments on commit be11a5b

Please sign in to comment.