add(command): overwrite arguments for app entry with provided arguments
This commit is contained in:
21
main.go
21
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"yves-biener.de/wish-serve/internal/serve"
|
||||
@@ -30,9 +31,29 @@ func loadConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite (default) configuration value for the application to serve with
|
||||
// given command line arguments.
|
||||
//
|
||||
// NOTE: This will also overwrite the configuration for the `app` entry from the
|
||||
// configuration file.
|
||||
func overwriteServeCommand() {
|
||||
if len(os.Args) >= 2 {
|
||||
name := os.Args[1]
|
||||
viper.Set("app.name", name)
|
||||
if len(os.Args) >= 3 {
|
||||
args := os.Args[2:]
|
||||
viper.Set("app.args", args)
|
||||
} else {
|
||||
// no arguments provided -> clear app arguments
|
||||
viper.Set("app.args", []string{})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
createDefaultConfig()
|
||||
loadConfig()
|
||||
overwriteServeCommand()
|
||||
|
||||
serve.Serve(
|
||||
viper.GetString("host"),
|
||||
|
||||
Reference in New Issue
Block a user