1
1
package main
2
2
3
3
import (
4
- "bytes"
5
4
"context"
6
- "encoding/json"
7
5
"fmt"
8
6
"io"
9
7
stdlog "log"
41
39
logFile := viper .GetString ("log-file" )
42
40
readOnly := viper .GetBool ("read-only" )
43
41
exportTranslations := viper .GetBool ("export-translations" )
44
- prettyPrintJSON := viper .GetBool ("pretty-print-json" )
45
42
logger , err := initLogger (logFile )
46
43
if err != nil {
47
44
stdlog .Fatal ("Failed to initialize logger:" , err )
52
49
logger : logger ,
53
50
logCommands : logCommands ,
54
51
exportTranslations : exportTranslations ,
55
- prettyPrintJSON : prettyPrintJSON ,
56
52
}
57
53
if err := runStdioServer (cfg ); err != nil {
58
54
stdlog .Fatal ("failed to run stdio server:" , err )
@@ -70,15 +66,13 @@ func init() {
70
66
rootCmd .PersistentFlags ().Bool ("enable-command-logging" , false , "When enabled, the server will log all command requests and responses to the log file" )
71
67
rootCmd .PersistentFlags ().Bool ("export-translations" , false , "Save translations to a JSON file" )
72
68
rootCmd .PersistentFlags ().String ("gh-host" , "" , "Specify the GitHub hostname (for GitHub Enterprise etc.)" )
73
- rootCmd .PersistentFlags ().Bool ("pretty-print-json" , false , "Pretty print JSON output" )
74
69
75
70
// Bind flag to viper
76
71
_ = viper .BindPFlag ("read-only" , rootCmd .PersistentFlags ().Lookup ("read-only" ))
77
72
_ = viper .BindPFlag ("log-file" , rootCmd .PersistentFlags ().Lookup ("log-file" ))
78
73
_ = viper .BindPFlag ("enable-command-logging" , rootCmd .PersistentFlags ().Lookup ("enable-command-logging" ))
79
74
_ = viper .BindPFlag ("export-translations" , rootCmd .PersistentFlags ().Lookup ("export-translations" ))
80
75
_ = viper .BindPFlag ("gh-host" , rootCmd .PersistentFlags ().Lookup ("gh-host" ))
81
- _ = viper .BindPFlag ("pretty-print-json" , rootCmd .PersistentFlags ().Lookup ("pretty-print-json" ))
82
76
83
77
// Add subcommands
84
78
rootCmd .AddCommand (stdioCmd )
@@ -112,20 +106,6 @@ type runConfig struct {
112
106
logger * log.Logger
113
107
logCommands bool
114
108
exportTranslations bool
115
- prettyPrintJSON bool
116
- }
117
-
118
- // JSONPrettyPrintWriter is a Writer that pretty prints input to indented JSON
119
- type JSONPrettyPrintWriter struct {
120
- writer io.Writer
121
- }
122
-
123
- func (j JSONPrettyPrintWriter ) Write (p []byte ) (n int , err error ) {
124
- var prettyJSON bytes.Buffer
125
- if err := json .Indent (& prettyJSON , p , "" , "\t " ); err != nil {
126
- return 0 , err
127
- }
128
- return j .writer .Write (prettyJSON .Bytes ())
129
109
}
130
110
131
111
func runStdioServer (cfg runConfig ) error {
@@ -179,9 +159,6 @@ func runStdioServer(cfg runConfig) error {
179
159
in , out = loggedIO , loggedIO
180
160
}
181
161
182
- if cfg .prettyPrintJSON {
183
- out = JSONPrettyPrintWriter {writer : out }
184
- }
185
162
errC <- stdioServer .Listen (ctx , in , out )
186
163
}()
187
164
0 commit comments