@@ -32,12 +32,14 @@ var (
32
32
Long :`Start a server that communicates via standard input/output streams using JSON-RPC messages.` ,
33
33
Run :func (cmd * cobra.Command ,args []string ) {
34
34
logFile := viper .GetString ("log-file" )
35
+ readOnly := viper .GetBool ("read-only" )
36
+ exportTranslations := viper .GetBool ("export-translations" )
35
37
logger ,err := initLogger (logFile )
36
38
if err != nil {
37
39
stdlog .Fatal ("Failed to initialize logger:" ,err )
38
40
}
39
41
logCommands := viper .GetBool ("enable-command-logging" )
40
- if err := runStdioServer (logger ,logCommands ,viper . GetBool ( "export-translations" ) );err != nil {
42
+ if err := runStdioServer (readOnly , logger ,logCommands ,exportTranslations );err != nil {
41
43
stdlog .Fatal ("failed to run stdio server:" ,err )
42
44
}
43
45
},
@@ -48,11 +50,13 @@ func init() {
48
50
cobra .OnInitialize (initConfig )
49
51
50
52
// Add global flags that will be shared by all commands
53
+ rootCmd .PersistentFlags ().Bool ("read-only" ,false ,"Restrict the server to read-only operations" )
51
54
rootCmd .PersistentFlags ().String ("log-file" ,"" ,"Path to log file" )
52
55
rootCmd .PersistentFlags ().Bool ("enable-command-logging" ,false ,"When enabled, the server will log all command requests and responses to the log file" )
53
56
rootCmd .PersistentFlags ().Bool ("export-translations" ,false ,"Save translations to a JSON file" )
54
57
55
58
// Bind flag to viper
59
+ viper .BindPFlag ("read-only" ,rootCmd .PersistentFlags ().Lookup ("read-only" ))
56
60
viper .BindPFlag ("log-file" ,rootCmd .PersistentFlags ().Lookup ("log-file" ))
57
61
viper .BindPFlag ("enable-command-logging" ,rootCmd .PersistentFlags ().Lookup ("enable-command-logging" ))
58
62
viper .BindPFlag ("export-translations" ,rootCmd .PersistentFlags ().Lookup ("export-translations" ))
@@ -84,7 +88,7 @@ func initLogger(outPath string) (*log.Logger, error) {
84
88
return logger ,nil
85
89
}
86
90
87
- func runStdioServer (logger * log.Logger ,logCommands bool ,exportTranslations bool )error {
91
+ func runStdioServer (readOnly bool , logger * log.Logger ,logCommands bool ,exportTranslations bool )error {
88
92
// Create app context
89
93
ctx ,stop := signal .NotifyContext (context .Background (),os .Interrupt ,syscall .SIGTERM )
90
94
defer stop ()
@@ -98,8 +102,8 @@ func runStdioServer(logger *log.Logger, logCommands bool, exportTranslations boo
98
102
99
103
t ,dumpTranslations := translations .TranslationHelper ()
100
104
101
- // Create server
102
- ghServer := github .NewServer (ghClient ,t )
105
+ // Create
106
+ ghServer := github .NewServer (ghClient ,readOnly , t )
103
107
stdioServer := server .NewStdioServer (ghServer )
104
108
105
109
stdLogger := stdlog .New (logger .Writer (),"stdioserver" ,0 )