// main
func main() {
- EnvConfFileMap := make(map[string]string)
+ var earlyDebug []string
// Allow to set app name from cli (useful for debugging)
if AppName == "" {
Value: defaultLogLevel,
},
cli.StringFlag{
- Name: "url",
+ Name: "url, u",
EnvVar: "XDS_SERVER_URL",
Value: "localhost:8000",
Usage: "remote XDS server url",
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
+ // Early and manual processing of --config option in order to set XDS_xxx
+ // variables before parsing of option by app cli
+ confFile := os.Getenv("XDS_CONFIG")
+ for idx, a := range os.Args[1:] {
+ if a == "-c" || a == "--config" || a == "-config" {
+ confFile = os.Args[idx+2]
+ break
+ }
+ }
+
+ // Load config file if requested
+ if confFile != "" {
+ earlyDebug = append(earlyDebug, fmt.Sprintf("confFile detected: %v", confFile))
+ if !common.Exists(confFile) {
+ exitError(1, "Error env config file not found")
+ }
+ // Load config file variables that will overwrite env variables
+ err := godotenv.Overload(confFile)
+ if err != nil {
+ exitError(1, "Error loading env config file "+confFile)
+ }
+
+ // Keep confFile settings in a map
+ EnvConfFileMap, err = godotenv.Read(confFile)
+ if err != nil {
+ exitError(1, "Error reading env config file "+confFile)
+ }
+ earlyDebug = append(earlyDebug, fmt.Sprintf("EnvConfFileMap: %v", EnvConfFileMap))
+ }
+
app.Before = func(ctx *cli.Context) error {
var err error
- // Don't init anything when user wants help
+ // Don't init anything when no argument or help option is set
+ if ctx.NArg() == 0 {
+ return nil
+ }
for _, a := range ctx.Args() {
switch a {
case "-h", "--h", "-help", "--help":
}
}
- // Load config file if requested
- confFile := ctx.String("config")
- if confFile != "" {
- if !common.Exists(confFile) {
- exitError(1, "Error env config file not found")
- }
- // Load config file variables that will overwrite env variables
- err := godotenv.Overload(confFile)
- if err != nil {
- exitError(1, "Error loading env config file "+confFile)
- }
- // Keep confFile settings in a map
- EnvConfFileMap, err = godotenv.Read(confFile)
- if err != nil {
- exitError(1, "Error reading env config file "+confFile)
- }
- }
-
loglevel := ctx.String("log")
// Set logger level and formatter
if Log.Level, err = logrus.ParseLevel(loglevel); err != nil {
Log.Formatter = &logrus.TextFormatter{}
Log.Infof("%s version: %s", AppName, app.Version)
- Log.Debugf("Environment: %v", os.Environ())
+ for _, str := range earlyDebug {
+ Log.Infof("%s", str)
+ }
+ Log.Debugf("\nEnvironment: %v\n", os.Environ())
if err = XdsConnInit(ctx); err != nil {
// Directly call HandleExitCoder to avoid to print help (ShowAppHelp)
// Define HTTP and WS url
baseURL := ctx.String("url")
- if !strings.HasPrefix(ctx.String("url"), "http://") {
- baseURL = "http://" + ctx.String("url")
+
+ // Allow to only set port number
+ if match, _ := regexp.MatchString("^([0-9]+)$", baseURL); match {
+ baseURL = "http://localhost:" + ctx.String("url")
+ }
+
+ // Add http prefix if missing
+ if !strings.HasPrefix(baseURL, "http://") {
+ baseURL = "http://" + baseURL
}
// Create HTTP client
return cli.NewExitError(errmsg, 1)
}
HTTPCli.SetLogLevel(ctx.String("loglevel"))
+ Log.Infoln("HTTP session ID : ", HTTPCli.GetClientID())
// Create io Websocket client
Log.Debugln("Connecting IO.socket client on ", baseURL)