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

Commit

Permalink
Ask for default execution type (docker / local) with RIT INIT (#480)
Browse files Browse the repository at this point in the history
* Add option to run rit with docker or local by default

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Fix lint

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Fix test

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Add stdin to rit set formula-runner command

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* add Apache license to file header

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create test for post_runner.go

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create more tests to cmd/formula.go

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Update README

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create more test to docker/runner

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create more test to docker/pre_runner

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create more test to docker/pre_run

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Create more test to docker/pre_run

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Fix tests

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Fix set formula runner cmd test name

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Adjust PR consideration

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>

* Remove comment

Signed-off-by: Kadu Artur Prussek <kadu.artur@gmail.com>
  • Loading branch information
kaduartur authored Sep 2, 2020
1 parent d5523ee commit 7bf3935
Show file tree
Hide file tree
Showing 34 changed files with 2,760 additions and 606 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![CircleCI](https://circleci.com/gh/ZupIT/ritchie-cli/tree/master.svg?style=svg)](https://circleci.com/gh/ZupIT/ritchie-cli) [![codecov](https://codecov.io/gh/zupit/ritchie-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/zupit/ritchie-cli) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![CircleCI](https://circleci.com/gh/ZupIT/ritchie-cli/tree/master.svg?style=svg)](https://circleci.com/gh/ZupIT/ritchie-cli)
[![codecov](https://codecov.io/gh/ZupIT/ritchie-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/ZupIT/ritchie-cli)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

<img class="special-img-class" src="/docs/img/ritchie-banner.png" />
<img class="special-img-class" src="/docs/img/ritchie-banner.png" alt="Ritchie logo with the phrase: Keep it simple"/>

## Ritchie - One CLI to rule them all

Expand Down
32 changes: 25 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/ZupIT/ritchie-cli/pkg/formula/creator/template"
"github.com/ZupIT/ritchie-cli/pkg/formula/repo"
"github.com/ZupIT/ritchie-cli/pkg/formula/runner"
"github.com/ZupIT/ritchie-cli/pkg/formula/runner/docker"
"github.com/ZupIT/ritchie-cli/pkg/formula/runner/local"
"github.com/ZupIT/ritchie-cli/pkg/formula/tree"
"github.com/ZupIT/ritchie-cli/pkg/git/github"
"github.com/ZupIT/ritchie-cli/pkg/git/gitlab"
Expand Down Expand Up @@ -58,7 +60,9 @@ func main() {
err := rootCmd.Execute()
if err != nil {
sendMetric(err.Error())
_, _ = fmt.Fprintf(os.Stderr, "Error: %+v\n", err)
errFmt := fmt.Sprintf("%+v", err)
errFmt = prompt.Red(errFmt)
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", errFmt)
os.Exit(1)
}

Expand Down Expand Up @@ -125,8 +129,20 @@ func buildCommands() *cobra.Command {

postRunner := runner.NewPostRunner(fileManager, dirManager)
inputManager := runner.NewInput(envResolvers, fileManager, inputList, inputText, inputBool, inputPassword)
formulaSetup := runner.NewPreRun(ritchieHomeDir, formBuildMake, formBuildDocker, formBuildBat, dirManager, fileManager)
formulaRunner := runner.NewFormulaRunner(postRunner, inputManager, formulaSetup, fileManager, ctxFinder, userHomeDir)

formulaLocalPreRun := local.NewPreRun(ritchieHomeDir, formBuildMake, formBuildBat, dirManager, fileManager)
formulaLocalRun := local.NewRunner(postRunner, inputManager, formulaLocalPreRun, fileManager, ctxFinder, userHomeDir)

formulaDockerPreRun := docker.NewPreRun(ritchieHomeDir, formBuildDocker, dirManager, fileManager)
formulaDockerRun := docker.NewRunner(postRunner, inputManager, formulaDockerPreRun, fileManager, ctxFinder, userHomeDir)

runners := formula.Runners{
formula.LocalRun: formulaLocalRun,
formula.DockerRun: formulaDockerRun,
}

configManager := runner.NewConfigManager(ritchieHomeDir, fileManager)
formulaExec := runner.NewExecutor(runners, configManager)

formulaCreator := creator.NewCreator(treeManager, dirManager, fileManager, tplManager)
formulaWorkspace := fworkspace.New(ritchieHomeDir, fileManager)
Expand All @@ -148,7 +164,7 @@ func buildCommands() *cobra.Command {
addCmd := cmd.NewAddCmd()
createCmd := cmd.NewCreateCmd()
deleteCmd := cmd.NewDeleteCmd()
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, inputList, fileManager)
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, configManager, fileManager, inputList, inputBool)
listCmd := cmd.NewListCmd()
setCmd := cmd.NewSetCmd()
showCmd := cmd.NewShowCmd()
Expand Down Expand Up @@ -184,6 +200,8 @@ func buildCommands() *cobra.Command {

createFormulaCmd := cmd.NewCreateFormulaCmd(userHomeDir, createBuilder, tplManager, formulaWorkspace, inputText, inputTextValidator, inputList, tutorialFinder)
buildFormulaCmd := cmd.NewBuildFormulaCmd(userHomeDir, formulaLocalBuilder, formulaWorkspace, watchManager, dirManager, inputText, inputList, tutorialFinder)
showFormulaRunnerCmd := cmd.NewShowFormulaRunnerCmd(configManager)
setFormulaRunnerCmd := cmd.NewSetFormulaRunnerCmd(configManager, inputList)

autocompleteCmd.AddCommand(autocompleteZsh, autocompleteBash, autocompleteFish, autocompletePowerShell)
addCmd.AddCommand(addRepoCmd)
Expand All @@ -192,11 +210,11 @@ func buildCommands() *cobra.Command {
deleteCmd.AddCommand(deleteCtxCmd, deleteRepoCmd)
listCmd.AddCommand(listRepoCmd)
listCmd.AddCommand(listCredentialCmd)
setCmd.AddCommand(setCredentialCmd, setCtxCmd, setPriorityCmd)
showCmd.AddCommand(showCtxCmd)
setCmd.AddCommand(setCredentialCmd, setCtxCmd, setPriorityCmd, setFormulaRunnerCmd)
showCmd.AddCommand(showCtxCmd, showFormulaRunnerCmd)
buildCmd.AddCommand(buildFormulaCmd)

formulaCmd := cmd.NewFormulaCommand(api.CoreCmds, treeManager, formulaRunner)
formulaCmd := cmd.NewFormulaCommand(api.CoreCmds, treeManager, formulaExec)
if err := formulaCmd.Add(rootCmd); err != nil {
panic(err)
}
Expand Down
5 changes: 5 additions & 0 deletions functional/init/init_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"key":"Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]",
"value":"yes",
"action":"select"
},
{
"key":"Select a default formula run type:",
"value":"local",
"action":"select"
}
],
"result":""
Expand Down
7 changes: 6 additions & 1 deletion functional/runner_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ func setUpRitSingleUnix() {
Key: "Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]",
Value: "yes",
Action: "select"}
initSetRunType := Step{
Key: "Select a default formula run type:",
Value: "local",
Action: "select",
}

init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepRit, initAcceptsMetrics, initAddRepo}}
init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepRit, initAcceptsMetrics, initAddRepo, initSetRunType}}

err, _ := init.runStepsForUnix()
if err != nil {
Expand Down
111 changes: 54 additions & 57 deletions functional/stdin/stdin_feature.json
Original file line number Diff line number Diff line change
@@ -1,101 +1,98 @@
[
{
"entry":"Init STDIN",
"steps":[
"entry": "Init STDIN",
"steps": [
{
"key":"",
"value":"{\"addRepo\":\"yes\"}",
"action":"echo"
"key": "",
"value": "{\"addCommons\": true,\"sendMetrics\": true, \"runType\": \"local\"}",
"action": "echo"
},
{
"key":"",
"value":"init --stdin",
"action":"main"
"key": "",
"value": "init --stdin",
"action": "main"
}

],
"result":"Initialization successful!"
"result": "Initialization successful!"
},
{
"entry":"Set context STDIN",
"steps":[
"entry": "Set context STDIN",
"steps": [
{
"key":"",
"value":"{\"context\":\"Leonidas\"}",
"action":"echo"
"key": "",
"value": "{\"context\":\"Leonidas\"}",
"action": "echo"
},
{
"key":"",
"value":"set context --stdin",
"action":"main"
"key": "",
"value": "set context --stdin",
"action": "main"
}

],
"result":"Set context successful!"
"result": "Set context successful!"
},
{
"entry":"Delete context STDIN",
"steps":[
"entry": "Delete context STDIN",
"steps": [
{
"key":"",
"value":"{\"context\":\"Leonidas\"}",
"action":"echo"
"key": "",
"value": "{\"context\":\"Leonidas\"}",
"action": "echo"
},
{
"key":"",
"value":"delete context --stdin",
"action":"main"
"key": "",
"value": "delete context --stdin",
"action": "main"
}

],
"result":"Delete context successful!"
"result": "Delete context successful!"
},
{
"entry":"Add new repo STDIN",
"steps":[
"entry": "Add new repo STDIN",
"steps": [
{
"key":"",
"value":"{\"provider\":\"Github\", \"name\":\"Leonidas\", \"url\":\"https://github.com/viniciussousazup/ritchie-formulas\", \"version\":\"0.0.3\",\"priority\":999}",
"action":"echo"
"key": "",
"value": "{\"provider\":\"Github\", \"name\":\"Leonidas\", \"url\":\"https://github.com/viniciussousazup/ritchie-formulas\", \"version\":\"0.0.3\",\"priority\":999}",
"action": "echo"
},
{
"key":"",
"value":"add repo --stdin",
"action":"main"
"key": "",
"value": "add repo --stdin",
"action": "main"
}
],
"result":""
"result": ""
},
{
"entry":"Delete repo STDIN",
"steps":[
"entry": "Delete repo STDIN",
"steps": [
{
"key":"",
"value":"{\"name\":\"Leonidas\"}",
"action":"echo"
"key": "",
"value": "{\"name\":\"Leonidas\"}",
"action": "echo"
},
{
"key":"",
"value":"delete repo --stdin",
"action":"main"
"key": "",
"value": "delete repo --stdin",
"action": "main"
}
],
"result":"\"Leonidas\" was deleted with success"
"result": "\"Leonidas\" was deleted with success"
},
{
"entry":"Set credentials STDIN",
"steps":[
"entry": "Set credentials STDIN",
"steps": [
{
"key":"",
"value":"{\"service\":\"Leonidas\",\"credential\": {\"username\":\"dmbarra\",\"token\": \"credentialToken\"}}",
"action":"echo"
"key": "",
"value": "{\"service\":\"Leonidas\",\"credential\": {\"username\":\"dmbarra\",\"token\": \"credentialToken\"}}",
"action": "echo"
},
{
"key":"",
"value":"set credential --stdin",
"action":"main"
"key": "",
"value": "set credential --stdin",
"action": "main"
}
],
"result":""
"result": ""
}
]
10 changes: 6 additions & 4 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package api

import (
"fmt"
"os/user"
"path/filepath"
"strings"
)

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

var (
Expand All @@ -48,8 +48,10 @@ var (
{Parent: "root_set", Usage: "context"},
{Parent: "root_set", Usage: "credential"},
{Parent: "root_set", Usage: "repo-priority"},
{Parent: "root_set", Usage: "formula-runner"},
{Parent: "root", Usage: "show"},
{Parent: "root_show", Usage: "context"},
{Parent: "root_show", Usage: "formula-runner"},
{Parent: "root", Usage: "create"},
{Parent: "root_create", Usage: "formula"},
{Parent: "root", Usage: "update"},
Expand Down Expand Up @@ -105,5 +107,5 @@ func UserHomeDir() string {

// RitchieHomeDir returns the home dir of the ritchie
func RitchieHomeDir() string {
return fmt.Sprintf(ritchieHomePattern, UserHomeDir())
return filepath.Join(UserHomeDir(), ritchieHomeName)
}
Loading

0 comments on commit 7bf3935

Please sign in to comment.