Skip to content

Commit 6b4d4bc

Browse files
refactor + multiple docker addresses handler
1 parent 8119811 commit 6b4d4bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+589
-496
lines changed

.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

.testing/devops/production/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44

55
source ./devops/ci_cd_vars.sh
66

7-
TARGET_IP="<ip_address_production>"
7+
TARGET_IP=<ip_address_production>
88
DOCKER_STACK_FILE="devops/production/docker-stack.yml"
99
STACK_NAME="ipsum"
1010
SERVICES_IN_STACK=("app" "cron")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source ./devops/ci_cd_vars.sh
6+
7+
IP_ADDRESSES=("ip_1" "ip_2" "ip_3")
8+
DOCKER_STACK_FILE="devops/production/docker-stack.yml"
9+
STACK_NAME="ipsum"
10+
SERVICES_IN_STACK=("app" "cron")

.testing/tugconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ssh_key_path": "test_key_path"
3+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ tug pm2 --check
6464
# Podstawowe użycie
6565
tug pm2
6666
```
67+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
// configureCmd represents the configure command
1313
var configureCmd = &cobra.Command{
1414
Use: "configure",
15-
Short: "Initialize configuration for tug",
15+
Short: "Configure tug",
1616
Run: func(cmd *cobra.Command, args []string) {
1717
container := dependecies.InitDependencyContainer()
18-
err := container.Invoke(func(configureUseCase *app.InitializeUseCase) error {
18+
err := container.Invoke(func(configureUseCase *app.ConfigureUseCase) error {
1919
return configureUseCase.Execute()
2020
})
2121
if err != nil {

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ func Execute() {
4141
}
4242

4343
func init() {
44+
rootCmd.CompletionOptions.HiddenDefaultCmd = true
4445
rootCmd.PersistentFlags().BoolP("version", "v", false, "Print version information")
4546
}

internal/adapters/sshconnector.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package adapters
22

33
import (
4-
"errors"
54
"fmt"
65
"net"
76
"os"
@@ -58,7 +57,7 @@ func (s *sshConnector) CloseConnection() error {
5857
func (s *sshConnector) loadSSHKeysFromDir() ([]ssh.AuthMethod, error) {
5958
tugConfig, err := tughelper.GetTugConfig()
6059
if err != nil {
61-
return nil, errors.New("Can not read tug config file, run `tug initialize` to configure tug.")
60+
return nil, fmt.Errorf("Can not read tug config file, run `tug configure` to configure tug. Error: %s", err)
6261
}
6362

6463
keyData, err := os.ReadFile(tugConfig.SSHKeyPath)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
"github.com/goodylabs/tug/pkg/config"
1010
)
1111

12-
type InitializeUseCase struct {
12+
type ConfigureUseCase struct {
1313
prompter ports.Prompter
1414
}
1515

16-
func NewInitializeUseCase(prompter ports.Prompter) *InitializeUseCase {
17-
return &InitializeUseCase{
16+
func NewConfigureUseCase(prompter ports.Prompter) *ConfigureUseCase {
17+
return &ConfigureUseCase{
1818
prompter: prompter,
1919
}
2020
}
2121

22-
func (i *InitializeUseCase) Execute() error {
23-
sshDirPath := filepath.Join(config.HOME_DIR, ".ssh")
22+
func (i *ConfigureUseCase) Execute() error {
23+
sshDirPath := filepath.Join(config.GetHomeDir(), ".ssh")
2424

2525
sshFiles, err := tughelper.GetAvailableSSHFiles(sshDirPath)
2626
if err != nil {
@@ -39,6 +39,6 @@ func (i *InitializeUseCase) Execute() error {
3939
return err
4040
}
4141

42-
fmt.Println("Tug configuration initialized successfully!")
42+
fmt.Println("Tug configuration configured successfully!")
4343
return nil
4444
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import (
55
"testing"
66

77
"github.com/goodylabs/tug/internal/tughelper"
8-
"github.com/goodylabs/tug/pkg/config"
98
"github.com/goodylabs/tug/tests/mocks"
109
"github.com/stretchr/testify/assert"
1110
)
1211

13-
func TestInitializeUseCaseOk(t *testing.T) {
12+
func TestConfigureUseCaseOk(t *testing.T) {
1413
testCases := []struct {
1514
promptChoices []int
1615
expected string
@@ -26,9 +25,9 @@ func TestInitializeUseCaseOk(t *testing.T) {
2625
}
2726

2827
for _, test := range testCases {
29-
os.Remove(config.TUG_CONFIG_PATH)
28+
os.Remove(tughelper.GetTugConfigPath())
3029

31-
useCase := mocks.SetupInitializeUseCaseWithMocks(test.promptChoices)
30+
useCase := mocks.SetupConfigureUseCaseWithMocks(test.promptChoices)
3231
err := useCase.Execute()
3332
assert.NoError(t, err)
3433

0 commit comments

Comments
 (0)