90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
package simon
|
|
|
|
// Author: Weisen Pan
|
|
// Date: 2023-10-24
|
|
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"./spf13/cobra"
|
|
"./spf13/pflag"
|
|
|
|
"./knets/knets_cmd/apply"
|
|
"./knets/knets_cmd/doc"
|
|
"./knets/knets_cmd/version"
|
|
)
|
|
|
|
const (
|
|
// EnvLogLevel is an environment variable to set the log level.
|
|
EnvLogLevel = "LOGLEVEL"
|
|
|
|
// LogPanic represents the "PANIC" log level.
|
|
LogPanic = "PANIC"
|
|
// LogFatal represents the "FATAL" log level.
|
|
LogFatal = "FATAL"
|
|
// LogError represents the "ERROR" log level.
|
|
LogError = "ERROR"
|
|
// LogWarn represents the "WARN" log level.
|
|
LogWarn = "WARN"
|
|
// LogInfo represents the "INFO" log level.
|
|
LogInfo = "INFO"
|
|
// LogDebug represents the "DEBUG" log level.
|
|
LogDebug = "DEBUG"
|
|
// LogTrace represents the "TRACE" log level.
|
|
LogTrace = "TRACE"
|
|
)
|
|
|
|
// NewSimonCommand creates a new Simon command.
|
|
func NewSimonCommand() *cobra.Command {
|
|
simonCmd := &cobra.Command{
|
|
Use: "simon",
|
|
Short: "Simon is a simulator for cluster workload scheduling.",
|
|
}
|
|
|
|
simonCmd.AddCommand(
|
|
version.VersionCmd,
|
|
apply.ApplyCmd,
|
|
doc.GenDoc.DocCmd,
|
|
)
|
|
|
|
// Set the normalization function for global flags.
|
|
simonCmd.SetGlobalNormalizationFunc(pflag.WordSepNormalizeFunc)
|
|
|
|
// Add Go flags to the command.
|
|
simonCmd.Flags().AddGoFlagSet(pflag.CommandLine)
|
|
|
|
// Disable automatic tag generation.
|
|
simonCmd.DisableAutoGenTag = true
|
|
|
|
return simonCmd
|
|
}
|
|
|
|
func init() {
|
|
// Get the log level from the environment variable.
|
|
logLevel := os.Getenv(EnvLogLevel)
|
|
|
|
// Set the log level based on the environment variable.
|
|
switch logLevel {
|
|
case LogPanic:
|
|
log.SetLevel(log.Panic)
|
|
case LogFatal:
|
|
log.SetLevel(log.Fatal)
|
|
case LogError:
|
|
log.SetLevel(log.Error)
|
|
case LogWarn:
|
|
log.SetLevel(log.Warn)
|
|
case LogInfo:
|
|
log.SetLevel(log.Info)
|
|
case LogDebug:
|
|
log.SetLevel(log.Debug)
|
|
case LogTrace:
|
|
log.SetLevel(log.Trace)
|
|
default:
|
|
// Default log level is INFO.
|
|
log.SetLevel(log.Info)
|
|
}
|
|
}
|