|
5 | 5 | "fmt" |
6 | 6 | "io" |
7 | 7 | stdlog"log" |
| 8 | +"net/url" |
8 | 9 | "os" |
9 | 10 | "os/signal" |
10 | 11 | "syscall" |
@@ -54,12 +55,14 @@ func init() { |
54 | 55 | rootCmd.PersistentFlags().String("log-file","","Path to log file") |
55 | 56 | rootCmd.PersistentFlags().Bool("enable-command-logging",false,"When enabled, the server will log all command requests and responses to the log file") |
56 | 57 | rootCmd.PersistentFlags().Bool("export-translations",false,"Save translations to a JSON file") |
| 58 | +rootCmd.PersistentFlags().String("gh-host","","Specify the GitHub hostname (for GitHub Enterprise etc.)") |
57 | 59 |
|
58 | 60 | // Bind flag to viper |
59 | 61 | viper.BindPFlag("read-only",rootCmd.PersistentFlags().Lookup("read-only")) |
60 | 62 | viper.BindPFlag("log-file",rootCmd.PersistentFlags().Lookup("log-file")) |
61 | 63 | viper.BindPFlag("enable-command-logging",rootCmd.PersistentFlags().Lookup("enable-command-logging")) |
62 | 64 | viper.BindPFlag("export-translations",rootCmd.PersistentFlags().Lookup("export-translations")) |
| 65 | +viper.BindPFlag("gh-host",rootCmd.PersistentFlags().Lookup("gh-host")) |
63 | 66 |
|
64 | 67 | // Add subcommands |
65 | 68 | rootCmd.AddCommand(stdioCmd) |
@@ -99,6 +102,20 @@ func runStdioServer(readOnly bool, logger *log.Logger, logCommands bool, exportT |
99 | 102 | logger.Fatal("GITHUB_PERSONAL_ACCESS_TOKEN not set") |
100 | 103 | } |
101 | 104 | ghClient:=gogithub.NewClient(nil).WithAuthToken(token) |
| 105 | +ifhost:=viper.GetString("gh-host");host!="" { |
| 106 | +parsedURL,err:=url.Parse(fmt.Sprintf("https://api.%s/",host)) |
| 107 | +iferr!=nil { |
| 108 | +returnfmt.Errorf("failed to parse provided GitHub host URL: %w",err) |
| 109 | +} |
| 110 | + |
| 111 | +uploadURL,err:=url.Parse(fmt.Sprintf("https://uploads.%s/",host)) |
| 112 | +iferr!=nil { |
| 113 | +returnfmt.Errorf("failed to parse provided GitHub host URL: %w",err) |
| 114 | +} |
| 115 | + |
| 116 | +ghClient.BaseURL=parsedURL |
| 117 | +ghClient.UploadURL=uploadURL |
| 118 | +} |
102 | 119 |
|
103 | 120 | t,dumpTranslations:=translations.TranslationHelper() |
104 | 121 |
|
|