@@ -22,13 +22,13 @@ var (
2222 jsonFilePath string
2323)
2424
25- // formatCmd representa o comando pai 'format'
25+ // formatCmd represents the 'format' parent command
2626var 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
3232var 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.
8181func 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.
100100func 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}
0 commit comments