[server] Allow setting working directory

This commit is contained in:
Abhishek Shroff
2025-05-02 01:40:46 +05:30
parent f93aee584f
commit 732986c79e
2 changed files with 8 additions and 1 deletions

View File

@@ -28,6 +28,8 @@ func SetupCommand() {
var rootCmd = &cobra.Command{Use: path.Base(os.Args[0])}
flags := rootCmd.PersistentFlags()
flags.StringP("workdir", "W", "", "Set working directory")
flags.Bool("debug", false, "Debug mode")
flags.MarkHidden("debug")
viper.BindPFlag("debug", flags.Lookup("debug"))
@@ -46,6 +48,11 @@ func SetupCommand() {
uuid.EnableRandPool()
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
dir, _ := cmd.Flags().GetString("workdir")
if dir != "" && dir != "." {
logrus.Info("Changing directory to " + dir)
os.Chdir(dir)
}
if viper.GetBool("debug") {
logrus.SetLevel(logrus.TraceLevel)
logrus.Debug("Running in debug mode")

View File

@@ -28,7 +28,7 @@ func createEngine(config *viper.Viper) *gin.Engine {
if config.GetBool("cors.enabled") {
origins := config.GetStringSlice("cors.origins")
logrus.Info("Enabling cors. Origins: " + strings.Join(origins, ", "))
logrus.Info("Enabling cors (" + strings.Join(origins, ", ") + ")")
engine.Use(cors.New(cors.Config{
AllowOrigins: origins,
AllowHeaders: []string{"Origin", "Authorization", "Accept", "Accept-Language", "Content-Type"},