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 #3 from ZupIT/fix/create_formula
Browse files Browse the repository at this point in the history
Fix create formula and binaries
  • Loading branch information
Marcos Guimarães authored Apr 9, 2020
2 parents 5c5ea31 + fca6b01 commit d3bc65f
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 240 deletions.
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Go parameters
TEAM=team
SINGLE=single
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOTOOLCOVER=$(GOCMD) tool cover
GOGET=$(GOCMD) get
BINARY_NAME=rit
CMD_PATH=./cmd/main.go
SINGLE_CMD_PATH=./cmd/$(SINGLE)/main.go
TEAM_CMD_PATH=./cmd/$(TEAM)/main.go
BIN=bin
TEAM=team
SINGLE=single
DIST=dist
DIST_MAC=$(DIST)/mac
DIST_MAC_TEAM=$(DIST_MAC)/$(TEAM)
Expand All @@ -31,17 +32,17 @@ RITCHIE_ENV=$(shell VERSION=$(VERSION) ./ritchie_env.sh)
build:
mkdir -p $(DIST_MAC_TEAM) $(DIST_MAC_SINGLE) $(DIST_LINUX_TEAM) $(DIST_LINUX_SINGLE) $(DIST_WIN_TEAM) $(DIST_WIN_SINGLE)
#LINUX
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER) ' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#MAC
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#WINDOWS 64
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(TEAM_CMD_PATH)
#LINUX SINGLE
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.Edition=$(SINGLE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_LINUX_SINGLE)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_LINUX_SINGLE)/$(BINARY_NAME) -v $(SINGLE_CMD_PATH)
#MAC SINGLE
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.Edition=$(SINGLE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_MAC_SINGLE)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_MAC_SINGLE)/$(BINARY_NAME) -v $(SINGLE_CMD_PATH)
#WINDOWS 64 SINGLE
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.Edition=$(SINGLE) -X $(MODULE)/pkg/env.ServerURL=$(RITCHIE_SERVER)' -o ./$(DIST_WIN_SINGLE)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_WIN_SINGLE)/$(BINARY_NAME).exe -v $(SINGLE_CMD_PATH)
ifneq "$(BUCKET)" ""
echo $(BUCKET)
aws s3 sync dist s3://$(BUCKET)/$(RELEASE_VERSION) --include "*"
Expand All @@ -54,26 +55,26 @@ endif
build-qa:
mkdir -p $(DIST_MAC_TEAM) $(DIST_MAC_SINGLE) $(DIST_LINUX_TEAM) $(DIST_LINUX_SINGLE) $(DIST_WIN_TEAM) $(DIST_WIN_SINGLE)
#LINUX
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#MAC
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#WINDOWS 64
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=https://ritchie-server.itiaws.dev' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(TEAM_CMD_PATH)
#LINUX SINGLE
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev -X $(MODULE)/pkg/env.Edition=$(SINGLE)' -o ./$(DIST_LINUX_SINGLE)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_LINUX_SINGLE)/$(BINARY_NAME) -v $(SINGLE_CMD_PATH)
#MAC SINGLE
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev -X $(MODULE)/pkg/env.Edition=$(SINGLE)' -o ./$(DIST_MAC_SINGLE)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_MAC_SINGLE)/$(BINARY_NAME) -v $(SINGLE_CMD_PATH)
#WINDOWS 64 SINGLE
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=https://ritchie-server.itiaws.dev -X $(MODULE)/pkg/env.Edition=$(SINGLE)' -o ./$(DIST_WIN_SINGLE)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=qa -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_WIN_SINGLE)/$(BINARY_NAME).exe -v $(SINGLE_CMD_PATH)

build-team-local:
mkdir -p $(DIST_MAC_TEAM) $(DIST_MAC_SINGLE) $(DIST_LINUX_TEAM)
#LINUX
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=http://localhost:8080' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=http://localhost:8080' -o ./$(DIST_LINUX_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#MAC
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=http://localhost:8080' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=http://localhost:8080' -o ./$(DIST_MAC_TEAM)/$(BINARY_NAME) -v $(TEAM_CMD_PATH)
#WINDOWS 64
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/env.ServerURL=http://localhost:8080' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=dev -X $(MODULE)/pkg/cmd.BuildDate=$(DATE) -X $(MODULE)/pkg/cmd.ServerURL=http://localhost:8080' -o ./$(DIST_WIN_TEAM)/$(BINARY_NAME).exe -v $(TEAM_CMD_PATH)

test:
mkdir -p $(BIN)
Expand Down
167 changes: 0 additions & 167 deletions cmd/main.go

This file was deleted.

104 changes: 104 additions & 0 deletions cmd/single/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"fmt"
"github.com/spf13/cobra"
"net/http"
"os"

"github.com/ZupIT/ritchie-cli/pkg/api"
"github.com/ZupIT/ritchie-cli/pkg/autocomplete"
"github.com/ZupIT/ritchie-cli/pkg/cmd"
"github.com/ZupIT/ritchie-cli/pkg/credential/credsingle"
"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/rcontext"
"github.com/ZupIT/ritchie-cli/pkg/security/secsingle"
"github.com/ZupIT/ritchie-cli/pkg/session"
"github.com/ZupIT/ritchie-cli/pkg/session/sesssingle"
"github.com/ZupIT/ritchie-cli/pkg/workspace"
)



func main() {
rootCmd := buildCommands()
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: %+v\n", err)
os.Exit(1)
}
}

func buildCommands() *cobra.Command {
userHomeDir := api.UserHomeDir()
ritchieHomeDir := api.RitchieHomeDir()

// deps
sessionManager := session.NewManager(ritchieHomeDir)
workspaceManager := workspace.NewChecker(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)
repoManager := formula.NewSingleRepoManager(ritchieHomeDir, http.DefaultClient, sessionManager)
sessionValidator := sesssingle.NewValidator(sessionManager)
loginManager := secsingle.NewLoginManager(sessionManager)
credSetter := credsingle.NewSetter(ritchieHomeDir, ctxFinder, sessionManager)
credFinder := credsingle.NewFinder(ritchieHomeDir, ctxFinder, sessionManager)
treeManager := formula.NewTreeManager(ritchieHomeDir, repoManager, api.SingleCoreCmds)
autocompleteGen := autocomplete.NewGenerator(treeManager)
credResolver := envcredential.NewResolver(credFinder)
envResolvers := make(env.Resolvers)
envResolvers[env.Credential] = credResolver
formulaRunner := formula.NewRunner(ritchieHomeDir, envResolvers, http.DefaultClient, treeManager)
formulaCreator := formula.NewCreator(userHomeDir, treeManager)

//commands
rootCmd := cmd.NewRootCmd(workspaceManager, loginManager, repoManager, sessionValidator, api.Single)

// level 1
autocompleteCmd := cmd.NewAutocompleteCmd()
addCmd := cmd.NewAddCmd()
cleanCmd := cmd.NewCleanCmd()
createCmd := cmd.NewCreateCmd()
deleteCmd := cmd.NewDeleteCmd()
listCmd := cmd.NewListCmd()
setCmd := cmd.NewSetCmd()
showCmd := cmd.NewShowCmd()
updateCmd := cmd.NewUpdateCmd()

// level 2
setCredentialCmd := cmd.NewSingleSetCredentialCmd(credSetter)
deleteCtxCmd := cmd.NewDeleteContextCmd(ctxFindRemover)
setCtxCmd := cmd.NewSetContextCmd(ctxFindSetter)
showCtxCmd := cmd.NewShowContextCmd(ctxFinder)
addRepoCmd := cmd.NewAddRepoCmd(repoManager)
cleanRepoCmd := cmd.NewCleanRepoCmd(repoManager)
deleteRepoCmd := cmd.NewDeleteRepoCmd(repoManager)
listRepoCmd := cmd.NewListRepoCmd(repoManager)
updateRepoCmd := cmd.NewUpdateRepoCmd(repoManager)
autocompleteZsh := cmd.NewAutocompleteZsh(autocompleteGen)
autocompleteBash := cmd.NewAutocompleteBash(autocompleteGen)
createFormulaCmd := cmd.NewCreateFormulaCmd(formulaCreator)

autocompleteCmd.AddCommand(autocompleteZsh, autocompleteBash)
addCmd.AddCommand(addRepoCmd)
cleanCmd.AddCommand(cleanRepoCmd)
createCmd.AddCommand(createFormulaCmd)
deleteCmd.AddCommand(deleteRepoCmd, deleteCtxCmd)
listCmd.AddCommand(listRepoCmd)
setCmd.AddCommand(setCredentialCmd, setCtxCmd)
showCmd.AddCommand(showCtxCmd)
updateCmd.AddCommand(updateRepoCmd)

rootCmd.AddCommand(addCmd, autocompleteCmd, cleanCmd, createCmd, deleteCmd, listCmd, setCmd, showCmd, updateCmd)

formulaCmd := cmd.NewFormulaCommand(api.SingleCoreCmds, treeManager, formulaRunner)
if err := formulaCmd.Add(rootCmd); err != nil {
panic(err)
}

return rootCmd
}
Loading

0 comments on commit d3bc65f

Please sign in to comment.