diff options
| author | Paul Buetow <paul@buetow.org> | 2021-09-28 21:11:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-02 12:26:36 +0300 |
| commit | 81b829e4e9f5ca0ac1df71c17f709af213b837ed (patch) | |
| tree | c4fc6b20404d0f922dc2825e4624be8c04479cbf /internal/config | |
| parent | a4d25626414ee36f937badd13e164aaf271c65d5 (diff) | |
can have daily and normal file log rotation
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/args.go | 43 | ||||
| -rw-r--r-- | internal/config/config.go | 43 | ||||
| -rw-r--r-- | internal/config/setup.go | 4 |
3 files changed, 45 insertions, 45 deletions
diff --git a/internal/config/args.go b/internal/config/args.go index 767cc65..7f24348 100644 --- a/internal/config/args.go +++ b/internal/config/args.go @@ -1,7 +1,6 @@ package config import ( - "flag" "fmt" "strings" @@ -68,48 +67,6 @@ func (a *Args) String() string { return sb.String() } -// Based on the argument list, transform/manipulate some of the arguments. -func (a *Args) transformConfig(args []string, client *ClientConfig, server *ServerConfig, common *CommonConfig) (*ClientConfig, *ServerConfig, *CommonConfig) { - if a.LogDir != "" { - common.LogDir = a.LogDir - if common.LogStrategy == "" { - // TODO: Implement the other (not-daily) log strategy for the server. - common.LogStrategy = "daily" - } - } - - if a.LogLevel != "" { - common.LogLevel = a.LogLevel - } - - if a.SSHPort != DefaultSSHPort { - common.SSHPort = a.SSHPort - } - if a.NoColor { - client.TermColorsEnable = false - } - - if a.Spartan { - a.Quiet = true - a.NoColor = true - } - - if a.Discovery == "" && a.ServersStr == "" { - a.Serverless = true - } - - // Interpret additional args as file list. - if a.What == "" { - var files []string - for _, file := range flag.Args() { - files = append(files, file) - } - a.What = strings.Join(files, ",") - } - - return client, server, common -} - // SerializeOptions returns a string ready to be sent over the wire to the server. func (a *Args) SerializeOptions() string { return fmt.Sprintf("quiet=%v:spartan=%v", a.Quiet, a.Spartan) diff --git a/internal/config/config.go b/internal/config/config.go index c9f411c..76dcc65 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "encoding/json" + "flag" "fmt" "io/ioutil" "os" @@ -78,3 +79,45 @@ func (c *configInitializer) parseSpecificConfig(configFile string) { panic(fmt.Sprintf("Unable to parse config file %s: %v", configFile, err)) } } + +func (c *configInitializer) transformConfig(args *Args, additionalArgs []string, + client *ClientConfig, server *ServerConfig, common *CommonConfig) (*ClientConfig, *ServerConfig, *CommonConfig) { + if args.LogDir != "" { + common.LogDir = args.LogDir + if common.LogStrategy == "" { + // TODO: Implement the other (not-daily) log strategy for the server. + common.LogStrategy = "daily" + } + } + + if args.LogLevel != "" { + common.LogLevel = args.LogLevel + } + + if args.SSHPort != DefaultSSHPort { + common.SSHPort = args.SSHPort + } + if args.NoColor { + client.TermColorsEnable = false + } + + if args.Spartan { + args.Quiet = true + args.NoColor = true + } + + if args.Discovery == "" && args.ServersStr == "" { + args.Serverless = true + } + + // Interpret additional args as file list. + if args.What == "" { + var files []string + for _, file := range flag.Args() { + files = append(files, file) + } + args.What = strings.Join(files, ",") + } + + return client, server, common +} diff --git a/internal/config/setup.go b/internal/config/setup.go index be8e867..7800914 100644 --- a/internal/config/setup.go +++ b/internal/config/setup.go @@ -8,8 +8,8 @@ func Setup(args *Args, additionalArgs []string) { Client: newDefaultClientConfig(), } initializer.parseConfig(args) - Client, Server, Common = args.transformConfig( - additionalArgs, + Client, Server, Common = initializer.transformConfig( + args, additionalArgs, initializer.Client, initializer.Server, initializer.Common, |
