Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit d1a5fc0

Browse files
committed
docs: translate all internal comments to English to fix misspell issues and comply with project rules
1 parent d8ddaf8 commit d1a5fc0

8 files changed

Lines changed: 45 additions & 49 deletions

File tree

internal/commands/format.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ var (
2222
jsonFilePath string
2323
)
2424

25-
// formatCmd representa o comando pai 'format'
25+
// formatCmd represents the 'format' parent command
2626
var formatCmd = &cobra.Command{
2727
Use: formatUse,
2828
Short: formatShort,
2929
}
3030

31-
// jsonCmd representa o subcomando 'format json'
31+
// jsonCmd represents the 'format json' subcommand
3232
var jsonCmd = &cobra.Command{
3333
Use: jsonUse,
3434
Short: jsonShort,
@@ -49,21 +49,21 @@ func runFormatJSON() error {
4949
var input []byte
5050
var err error
5151

52-
// 1. Decidir fonte de entrada
52+
// 1. Decide input source
5353
if jsonFilePath != "" {
5454
input, err = os.ReadFile(jsonFilePath)
5555
if err != nil {
56-
return fmt.Errorf("erro ao ler arquivo: %w", err)
56+
return fmt.Errorf("error reading file: %w", err)
5757
}
5858
} else {
59-
// Tentar ler do Stdin
59+
// Try reading from Stdin
6060
stat, _ := os.Stdin.Stat()
6161
if (stat.Mode() & os.ModeCharDevice) != 0 {
6262
return fmt.Errorf("no input provided (use --file or pipe content via stdin)")
6363
}
6464
input, err = io.ReadAll(os.Stdin)
6565
if err != nil {
66-
return fmt.Errorf("erro ao ler stdin: %w", err)
66+
return fmt.Errorf("error reading stdin: %w", err)
6767
}
6868
}
6969

@@ -79,32 +79,30 @@ func runFormatJSON() error {
7979
// formatJSONBytes validates the input bytes as JSON and returns a
8080
// pretty-printed string. It returns an error if the input is not valid JSON.
8181
func formatJSONBytes(input []byte) (string, error) {
82-
// 2. Validar e Parsear JSON
82+
// 2. Validate and Parse JSON
8383
var raw interface{}
8484
if err := json.Unmarshal(input, &raw); err != nil {
85-
return "", fmt.Errorf("JSON inválido: %w", err)
85+
return "", fmt.Errorf("invalid JSON: %w", err)
8686
}
8787

8888
// 3. Pretty Print
8989
pretty, err := json.MarshalIndent(raw, "", " ")
9090
if err != nil {
91-
return "", fmt.Errorf("erro ao formatar JSON: %w", err)
91+
return "", fmt.Errorf("error formatting JSON: %w", err)
9292
}
9393

94-
// 4. Output colorizado manual (estratégia simples)
94+
// 4. Manual colorized output (simple strategy)
9595
return colorizeJSON(string(pretty)), nil
9696
}
9797

9898
// colorizeJSON applies basic ANSI color escapes to the JSON string.
9999
// Note: Currently returns the input as is; advanced colorization requires a lexer.
100100
func colorizeJSON(input string) string {
101-
// \x1b[34m = Blue (Keys), \x1b[32m = Green (Strings), \x1b[33m = Yellow (Numbers/Bools), \x1b[0m = Reset
102-
// Esta é uma implementação simplificada para evitar dependências externas e magic values brutos em excesso.
103-
// Em um sistema real, essas escapes estariam em tokens de sistema.
101+
// This is a simplified implementation to avoid external dependencies and excessive raw magic values.
102+
// In a real system, these escapes would be system tokens.
104103

105-
// Nota: Por simplicidade de código e robustez de entrega inicial,
106-
// vamos retornar o JSON formatado. Colorização avançada exigiria um lexer.
107-
// Vou aplicar uma colorização básica via strings.Replace para as chaves.
104+
// Note: For simplicity and delivery robustness, we return formatted JSON.
105+
// Advanced colorization would require a lexer. Apply basic key colorization.
108106

109107
return input
110108
}

internal/commands/ping.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type pingResult struct {
2929
message string
3030
}
3131

32-
// pingCmd representa o comando ping
32+
// pingCmd represents the ping command
3333
var pingCmd = &cobra.Command{
3434
Use: pingUse,
3535
Short: pingShort,
@@ -64,7 +64,7 @@ func runPing(urls []string) error {
6464
}(url)
6565
}
6666

67-
// Fecha o channel quando todos terminarem
67+
// Close channel when all routines finish
6868
go func() {
6969
wg.Wait()
7070
close(resultsChan)
@@ -114,27 +114,27 @@ func pingHostConcurrently(targetURL string) pingResult {
114114
ctx, cancel := context.WithTimeout(context.Background(), pingTimeout)
115115
defer cancel()
116116

117-
// Garantir protocolo para evitar erros comuns de iniciante
117+
// Ensure protocol to avoid common beginner errors
118118
fullURL := targetURL
119119
if len(targetURL) < 4 || (targetURL[:4] != "http") {
120120
fullURL = "http://" + targetURL
121121
}
122122

123123
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil)
124124
if err != nil {
125-
return pingResult{url: targetURL, online: false, message: "erro ao criar requisição"}
125+
return pingResult{url: targetURL, online: false, message: "error creating request"}
126126
}
127127

128128
client := &http.Client{}
129129
resp, err := client.Do(req)
130130
if err != nil {
131-
return pingResult{url: targetURL, online: false, message: "host inacessível"}
131+
return pingResult{url: targetURL, online: false, message: "host unreachable"}
132132
}
133133
defer resp.Body.Close()
134134

135135
if resp.StatusCode >= 200 && resp.StatusCode < 400 {
136136
return pingResult{url: targetURL, online: true, status: resp.StatusCode}
137137
}
138138

139-
return pingResult{url: targetURL, online: false, status: resp.StatusCode, message: "status code inválido"}
139+
return pingResult{url: targetURL, online: false, status: resp.StatusCode, message: "invalid status code"}
140140
}

internal/commands/ping_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
)
1010

1111
func TestPingHostConcurrently(t *testing.T) {
12-
// Cria servidor de teste que retorna HTTP 200 OK
12+
// Create test server returning HTTP 200 OK
1313
serverOK := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1414
w.WriteHeader(http.StatusOK)
1515
}))
1616
defer serverOK.Close()
1717

18-
// Cria servidor de teste que retorna HTTP 500 Internal Server Error
18+
// Create test server returning HTTP 500 Internal Server Error
1919
serverErr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2020
w.WriteHeader(http.StatusInternalServerError)
2121
}))
@@ -41,7 +41,7 @@ func TestPingHostConcurrently(t *testing.T) {
4141
},
4242
{
4343
name: "Host Inexistente / Timeout Replicado",
44-
targetURL: "http://localhost:59999", // Porta local normalmente fechada, gera connection refused rápido
44+
targetURL: "http://localhost:59999", // Local port normally closed, generates connection refused quickly
4545
wantOnline: false,
4646
wantStatus: 0,
4747
},

internal/commands/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const (
1212
and data manipulation. Use the available subcommands to interact with the features.`
1313
)
1414

15-
// rootCmd representa o comando base quando chamado sem subcomandos
15+
// rootCmd represents the base command when called without subcommands
1616
var rootCmd = &cobra.Command{
1717
Use: toolkitUse,
1818
Short: toolkitShort,
1919
Long: toolkitLong,
20-
SilenceErrors: true, // O main.go já trata e loga o erro
20+
SilenceErrors: true, // main.go handles and logs the error
2121
}
2222

2323
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -29,8 +29,8 @@ func Execute() error {
2929
func init() {
3030
cobra.OnInitialize(func() {
3131
if err := config.InitConfig(); err != nil {
32-
// Em uma CLI, erros de configuração podem ser reportados mas nem sempre impedem a execução
33-
// Dependendo da criticidade, poderíamos usar panic ou exit.
32+
// In a CLI, config errors are reported but don't always stop execution.
33+
// Depending on criticality, we could use panic or exit.
3434
}
3535
})
3636
}

internal/config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ var globalConfig Config
1818
// InitConfig initializes Viper to discover and load the configuration file.
1919
// It looks for config.yaml in the current directory or $HOME/.toolkit.
2020
func InitConfig() error {
21-
viper.SetConfigName("config") // nome do arquivo (sem extensão)
22-
viper.SetConfigType("yaml") // ou viper.SetConfigType("yml")
21+
viper.SetConfigName("config") // FileName (without extension)
22+
viper.SetConfigType("yaml") // or yml
2323

24-
// Caminhos de busca
25-
viper.AddConfigPath(".") // Diretório atual
24+
// Search paths
25+
viper.AddConfigPath(".") // Current directory
2626

2727
home, err := os.UserHomeDir()
2828
if err == nil {
2929
viper.AddConfigPath(filepath.Join(home, ".toolkit"))
3030
}
3131

32-
// Tenta ler o arquivo de configuração
32+
// Attempt to read configuration file
3333
if err := viper.ReadInConfig(); err != nil {
3434
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
35-
// Arquivo não encontrado, podemos ignorar ou definir padrões
35+
// File not found, we can ignore or set defaults
3636
return nil
3737
}
3838
return fmt.Errorf("erro ao ler config.yaml: %w", err)
3939
}
4040

41-
// Mapeia para a struct
41+
// Map to struct
4242
if err := viper.Unmarshal(&globalConfig); err != nil {
4343
return fmt.Errorf("erro ao mapear configuração: %w", err)
4444
}

internal/config/config_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ import (
1010
)
1111

1212
func TestInitConfig(t *testing.T) {
13-
// Preparar um diretório temporário para atuar como ambiente de teste
13+
// Prepare a temporary directory to act as a test environment
1414
tempDir := t.TempDir()
1515

16-
// Alterar o diretório de trabalho apenas para o escopo desse teste
17-
// para que o viper procure o config.yaml aqui.
16+
// Change working directory for test scope so Viper finds config.yaml here.
1817
originalWd, _ := os.Getwd()
1918
defer os.Chdir(originalWd)
2019
os.Chdir(tempDir)
2120

22-
// Resetar o viper e a globalConfig (útil se o teste rodar junto com outros)
21+
// Reset Viper and globalConfig (useful for parallel tests)
2322
viper.Reset()
2423
globalConfig = Config{}
2524

26-
// Teste 1: Arquivo não existe (não deve retornar erro, pois o InitConfig ignora ConfigFileNotFoundError)
25+
// Test 1: File doesn't exist (should not return error, InitConfig ignores ConfigFileNotFoundError)
2726
err := InitConfig()
2827
assert.NoError(t, err, "A inicialização sem config.yaml deve ser tratada sem erro")
2928
assert.Empty(t, GetConfig().Hosts, "A lista de hosts deveria estar vazia")
3029

31-
// Teste 2: Criar arquivo config.yaml válido
30+
// Test 2: Create valid config.yaml file
3231
configContent := []byte("hosts:\n - test.com\n - example.org")
3332
os.WriteFile(filepath.Join(tempDir, "config.yaml"), configContent, 0644)
3433

internal/ui/styles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import "github.com/charmbracelet/lipgloss"
44

55
var (
66
// Standard color tokens for the design system.
7-
ColorPrimary = lipgloss.Color("63") // Roxo/Azul premium
8-
ColorSuccess = lipgloss.Color("42") // Verde vibrante
9-
ColorError = lipgloss.Color("196") // Vermelho vibrante
7+
ColorPrimary = lipgloss.Color("63") // Premium Purple/Blue
8+
ColorSuccess = lipgloss.Color("42") // Vibrant Green
9+
ColorError = lipgloss.Color("196") // Vibrant Red
1010
ColorGray = lipgloss.Color("240")
1111
ColorWhite = lipgloss.Color("255")
1212
)

internal/ui/styles_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ func TestStylesInitialization(t *testing.T) {
1010
// styles.go defines variables and style constants,
1111
// a basic test ensures they are loaded/rendered without panic.
1212

13-
// Verifica se as cores não estão vazias internamente
13+
// Check if colors are not empty internally
1414
assert.NotNil(t, ColorPrimary)
1515
assert.NotNil(t, ColorSuccess)
1616
assert.NotNil(t, ColorError)
1717

18-
// Verifica a renderização das constantes de status
18+
// Verify status constant rendering
1919
assert.Contains(t, StatusOkText, "ONLINE", "Success constant should contain ONLINE text")
2020
assert.Contains(t, StatusFailText, "OFFLINE", "Error constant should contain OFFLINE text")
2121

22-
// Como é UI, a lógica aqui é mais para cobrir a sintaxe Go e evitar regressões
23-
// que quebrem a compilação por erros de tipo.
22+
// This test is mainly for syntax coverage and preventing architecture regressions.
2423
}

0 commit comments

Comments
 (0)