This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ZupIT/fix/create_formula
Fix create formula and binaries
- Loading branch information
Showing
18 changed files
with
365 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.