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

Switch context to env command #706

Merged
merged 14 commits into from
Dec 8, 2020
Merged
30 changes: 15 additions & 15 deletions functional/core/core_feature.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
[
{
"entry": "Show context",
"entry": "Show env",
"steps": [
{
"key": "",
"value": "show context",
"value": "show env",
"action": "main"
}
],
"result": "Current context:"
"result": "Current env:"
},
{
"entry": "Set context",
"entry": "Set env",
"steps": [
{
"key": "",
"value": "set context",
"value": "set env",
"action": "main"
},
{
"key": "All:",
"value": "Type new context?",
"value": "Type the new env?",
"action": "select"
},
{
"key": "New context:",
"key": "New env:",
"value": "Leonidas",
"action": "sendkey"
}
],
"result": "Set context successful!"
"result": "Set env successful!"
},
{
"entry": "Delete context",
"entry": "Delete env",
"steps": [
{
"key": "",
"value": "delete context",
"value": "delete env",
"action": "main"
},
{
Expand All @@ -45,12 +45,12 @@
"action": "select"
},
{
"key": "Are you sure want to delete this context?",
"key": "Are you sure want to delete this env?",
"value": "yes",
"action": "select"
}
],
"result": "Delete context successful!"
"result": "Delete env successful!"
},
{
"entry": "Add",
Expand Down Expand Up @@ -193,7 +193,7 @@
"action": "main"
}
],
"result": "Set contexts, credentials, priorities for formula repositories and formulas runner defaults."
"result": "Set envs, credentials, priorities for formula repositories and formulas runner defaults."
},
{
"entry": "Update",
Expand Down Expand Up @@ -292,7 +292,7 @@
"action": "main"
}
],
"result": "Delete contexts, repositories, formulas, workspaces and credentials"
"result": "Delete env, repositories, formulas, workspaces and credentials"
},
{
"entry": "Show",
Expand All @@ -303,7 +303,7 @@
"action": "main"
}
],
"result": "Show current context and formula-runnner default"
"result": "Show current env and formula-runner default"
},
{
"entry": "Create",
Expand Down
18 changes: 9 additions & 9 deletions functional/init/init_feature.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[
{
"entry":"Show context",
"entry":"Show env",
"steps":[
{
"key":"",
"value":"show context",
"value":"show env",
"action":"main"
}
],
"result":"Current context: default"
"result":"Current env: \"default\""
},
{
"entry":"Set context",
"entry":"Set env",
"steps":[
{
"key":"",
"value":"set context",
"value":"set env",
"action":"main"
},
{
Expand All @@ -24,18 +24,18 @@
"action": "select"
}
],
"result":"Set context successful!"
"result":"Set env successful!"
},
{
"entry":"Delete context",
"entry":"Delete env",
"steps":[
{
"key":"",
"value":"delete context",
"value":"delete env",
"action":"main"
}
],
"result":"You have no defined contexts"
"result":"You have no defined envs"
},
{
"entry":"List repo",
Expand Down
6 changes: 3 additions & 3 deletions functional/init/init_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ var _ = Describe("RitSingleInit", func() {
Expect(out).To(ContainSubstring(scenario.Result))
},

Entry("Show context", scenariosCore[0]),
Entry("Set context", scenariosCore[1]),
Entry("Delete context", scenariosCore[2]),
Entry("Show env", scenariosCore[0]),
Entry("Set env", scenariosCore[1]),
Entry("Delete env", scenariosCore[2]),
Entry("List repo", scenariosCore[3]),
Entry("Delete repo", scenariosCore[4]),
Entry("Create formula", scenariosCore[5]),
Expand Down
16 changes: 8 additions & 8 deletions functional/stdin/stdin_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@
"result": "Initialization successful!"
},
{
"entry": "Set context STDIN",
"entry": "Set env STDIN",
"steps": [
{
"key": "",
"value": "{\"context\":\"Leonidas\"}",
"value": "{\"env\":\"Leonidas\"}",
"action": "echo"
},
{
"key": "",
"value": "set context --stdin",
"value": "set env --stdin",
"action": "main"
}
],
"result": "Set context successful!"
"result": "Set env successful!"
},
{
"entry": "Delete context STDIN",
"entry": "Delete env STDIN",
"steps": [
{
"key": "",
"value": "{\"context\":\"Leonidas\"}",
"value": "{\"env\":\"Leonidas\"}",
"action": "echo"
},
{
"key": "",
"value": "delete context --stdin",
"value": "delete env --stdin",
"action": "main"
}
],
"result": "Delete context successful!"
"result": "Delete env successful!"
},
{
"entry": "Add new repo STDIN",
Expand Down
96 changes: 96 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/sh

usage () {
echo "./install.sh"
}


idempotent_config() {
if [ -n "$SHELL_TYPE" ]; then

if [ -f ${HOME}"/."${SHELL_TYPE}"rc" ]; then

sed -i'' -e '/source <(rit completion/d' ${HOME}"/."${SHELL_TYPE}"rc"

if grep "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" ~/."${SHELL_TYPE}"rc > /dev/null
then
echo ".${SHELL_TYPE}rc IS ALREADY CONFIGURED TO SUPPORT RITCHIE AUTO COMPLETION"
else
echo "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" >> ~/."${SHELL_TYPE}"rc
echo "source ~/.rit_completion" >> ~/."${SHELL_TYPE}"rc
fi

elif [ -f ${HOME}"/."${SHELL_TYPE}"_profile" ]; then

sed -i'' -e '/source <(rit completion/d' ${HOME}"/."${SHELL_TYPE}"_profile"

if grep "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" ~/."${SHELL_TYPE}"_profile > /dev/null
then
echo ".${SHELL_TYPE}_profile IS ALREADY CONFIGURED TO SUPPORT RITCHIE AUTO COMPLETION"
else
echo "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" >> ~/."${SHELL_TYPE}"_profile
echo "source ~/.rit_completion" >> ~/."${SHELL_TYPE}"_profile
fi

else
echo "Installed Ritchie without autocomplete"
return
fi


echo "Installed Ritchie with autocomplete"
fi
}

rit_install () {
echo "Downloading rit..."
STABLE_VERSION=$(curl -s https://commons-repo.ritchiecli.io/stable.txt)
curl -SLO "https://commons-repo.ritchiecli.io/${STABLE_VERSION}/${OPERATIONAL_SYSTEM}/rit"


chmod +x ./rit

INSTALL_PATH="/usr/local/bin"

if [ ! -d "$INSTALL_PATH" ]; then
sudo mkdir -p $INSTALL_PATH
fi

sudo mv ./rit $INSTALL_PATH/rit
$INSTALL_PATH/rit --version

idempotent_config
}

rit_identify_shell () {
if [ -n "$($SHELL -c 'echo $ZSH_VERSION')" ]; then
echo "Going to install autocomplete for zsh"
SHELL_TYPE="zsh"
elif [ -n "$($SHELL -c 'echo $BASH_VERSION')" ]; then
echo "Going to install autocomplete for bash"
SHELL_TYPE="bash"
else
echo "Please consider using bash or zsh to improve your ritchie experience"
SHELL_TYPE=""
fi
}

rit_identify_os () {

if [ $(uname) = "Linux" ]; then
echo "Installing Ritchie for Linux"
OPERATIONAL_SYSTEM="linux"
elif [ $(uname) = "Darwin" ]; then
echo "Installing Ritchie for Mac"
OPERATIONAL_SYSTEM="darwin"
else
echo "Unable to identify which OS you're using"
exit 1
fi
}

rit_identify_os

rit_identify_shell

rit_install
9 changes: 5 additions & 4 deletions internal/mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
package mocks

import (
"github.com/ZupIT/ritchie-cli/pkg/formula"
"github.com/ZupIT/ritchie-cli/pkg/rcontext"
"github.com/stretchr/testify/mock"

"github.com/ZupIT/ritchie-cli/pkg/env"
"github.com/ZupIT/ritchie-cli/pkg/formula"
)

type ContextFinderMock struct {
kaduartur marked this conversation as resolved.
Show resolved Hide resolved
mock.Mock
}

func (cf *ContextFinderMock) Find() (rcontext.ContextHolder, error) {
func (cf *ContextFinderMock) Find() (env.Holder, error) {
args := cf.Called()

return args.Get(0).(rcontext.ContextHolder), args.Error(1)
return args.Get(0).(env.Holder), args.Error(1)
}

type DetailManagerMock struct {
Expand Down
Empty file modified packaging/scripts/postinst.sh
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
{Parent: "root_completion", Usage: "fish"},
{Parent: "root_completion", Usage: "powershell"},
{Parent: "root", Usage: "delete"},
{Parent: "root_delete", Usage: "context"},
{Parent: "root_delete", Usage: "env"},
{Parent: "root_delete", Usage: "repo"},
{Parent: "root_delete", Usage: "workspace"},
{Parent: "root_delete", Usage: "formula"},
Expand All @@ -50,12 +50,12 @@ var (
{Parent: "root_list", Usage: "credential"},
{Parent: "root_list", Usage: "workspace"},
{Parent: "root", Usage: "set"},
{Parent: "root_set", Usage: "context"},
{Parent: "root_set", Usage: "env"},
{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: "env"},
{Parent: "root_show", Usage: "formula-runner"},
{Parent: "root", Usage: "create"},
{Parent: "root_create", Usage: "formula"},
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ func RunFuncE(stdinFunc, promptFunc CommandRunnerFunc) CommandRunnerFunc {
return promptFunc(cmd, args)
}
}

func DeprecateCmd(parentCmd *cobra.Command, deprecatedCmd, deprecatedMsg string) {
command := &cobra.Command{
Use: deprecatedCmd,
Deprecated: deprecatedMsg,
}
parentCmd.AddCommand(command)
}
28 changes: 22 additions & 6 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,32 @@

package cmd

import "github.com/spf13/cobra"
import (
"fmt"

"github.com/spf13/cobra"

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

// NewDeleteCmd create a new delete instance.
func NewDeleteCmd() *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "delete SUBCOMMAND",
Short: "Delete contexts, repositories, formulas, workspaces and credentials",
Long: "Delete contexts, repositories, formulas, workspaces and credentials",
Example: "rit delete context",
ValidArgs: []string{"context", "formula", "repo", "workspace", "credential"},
Short: "Delete env, repositories, formulas, workspaces and credentials",
Long: "Delete env, repositories, formulas, workspaces and credentials",
Example: "rit delete env",
ValidArgs: []string{"env", "formula", "repo", "workspace", "credential"},
Args: cobra.OnlyValidArgs,
}

deprecatedMsg := fmt.Sprintf(
`you can now use the "%v" command for the same purpose as the "%v" command.`,
prompt.Bold("rit delete env"),
prompt.Bold("rit delete context"),
)

DeprecateCmd(cmd, "context", deprecatedMsg)

return cmd
}
Loading