mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
iris run main.go - prints the iris' logger but doesn't prints the banner everytime
This commit is contained in:
parent
e72a8f6786
commit
5cf18b264e
|
@ -1,6 +1,7 @@
|
||||||
package iris
|
package iris
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -78,6 +79,14 @@ type Framework struct {
|
||||||
Websocket websocket.Server
|
Websocket websocket.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SkipBannerFlag, if enabled then means that this instance ran propably by an external software, which can disable the banner output by the command line argument '-s'
|
||||||
|
var SkipBannerFlag bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&SkipBannerFlag, "s", false, "Disable banner via command line tool, overrides the logger's config field") // this mostly used by the iris command line tool
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
// New creates and returns a new Iris station aka Framework.
|
// New creates and returns a new Iris station aka Framework.
|
||||||
//
|
//
|
||||||
// Receives an optional config.Iris as parameter
|
// Receives an optional config.Iris as parameter
|
||||||
|
@ -161,7 +170,9 @@ func (s *Framework) openServer() (err error) {
|
||||||
s.HTTPServer.SetHandler(s.mux)
|
s.HTTPServer.SetHandler(s.mux)
|
||||||
if err = s.HTTPServer.Open(); err == nil {
|
if err = s.HTTPServer.Open(); err == nil {
|
||||||
// print the banner
|
// print the banner
|
||||||
if !s.Config.DisableBanner {
|
if s.Config.DisableBanner || SkipBannerFlag {
|
||||||
|
// skip the banner
|
||||||
|
} else {
|
||||||
s.Logger.PrintBanner(banner,
|
s.Logger.PrintBanner(banner,
|
||||||
fmt.Sprintf("%s: Running at %s\n", time.Now().Format(config.TimeFormat),
|
fmt.Sprintf("%s: Running at %s\n", time.Now().Format(config.TimeFormat),
|
||||||
s.HTTPServer.Host()))
|
s.HTTPServer.Host()))
|
||||||
|
|
|
@ -7,7 +7,7 @@ This package is the command line tool for [../](https://github.com/kataras/iris
|
||||||
[![Iris installed screen](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen2.png)](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen2.png)
|
[![Iris installed screen](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen2.png)](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen2.png)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
Current version: 0.0.7
|
Current version: 0.0.8
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
go get -u github.com/kataras/iris/iris
|
go get -u github.com/kataras/iris/iris
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.7"
|
Version = "0.0.8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
23
iris/run.go
23
iris/run.go
|
@ -23,6 +23,8 @@ var (
|
||||||
goExt = ".go"
|
goExt = ".go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var times uint32 = 0
|
||||||
|
|
||||||
func build(sourcepath string) error {
|
func build(sourcepath string) error {
|
||||||
goBuild := utils.CommandBuilder("go", "build", sourcepath)
|
goBuild := utils.CommandBuilder("go", "build", sourcepath)
|
||||||
goBuild.Dir = workingDir
|
goBuild.Dir = workingDir
|
||||||
|
@ -36,13 +38,14 @@ func build(sourcepath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(executablePath string, stdout bool) (*utils.Cmd, error) {
|
func run(executablePath string) (*utils.Cmd, error) {
|
||||||
runCmd := utils.CommandBuilder("." + utils.PathSeparator + executablePath)
|
runCmd := utils.CommandBuilder("." + utils.PathSeparator + executablePath)
|
||||||
|
if times >= 1 {
|
||||||
|
runCmd.AppendArguments("-s") //-s to skip the banner after the first time
|
||||||
|
}
|
||||||
runCmd.Dir = workingDir
|
runCmd.Dir = workingDir
|
||||||
runCmd.Stderr = os.Stderr
|
runCmd.Stderr = os.Stderr
|
||||||
if stdout {
|
|
||||||
runCmd.Stdout = os.Stdout
|
runCmd.Stdout = os.Stdout
|
||||||
}
|
|
||||||
|
|
||||||
runCmd.Stderr = os.Stderr
|
runCmd.Stderr = os.Stderr
|
||||||
if err := runCmd.Start(); err != nil {
|
if err := runCmd.Start(); err != nil {
|
||||||
|
@ -50,6 +53,7 @@ func run(executablePath string, stdout bool) (*utils.Cmd, error) {
|
||||||
printer.Dangerf(ferr.Error())
|
printer.Dangerf(ferr.Error())
|
||||||
return nil, ferr
|
return nil, ferr
|
||||||
}
|
}
|
||||||
|
times++
|
||||||
return runCmd, nil
|
return runCmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +126,7 @@ func runAndWatch(flags cli.Flags) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd, err := run(executablePath, true)
|
runCmd, err := run(executablePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printer.Dangerf(err.Error())
|
printer.Dangerf(err.Error())
|
||||||
|
@ -133,7 +137,7 @@ func runAndWatch(flags cli.Flags) error {
|
||||||
printer.Dangerf("")
|
printer.Dangerf("")
|
||||||
printer.Panic(errUnexpected)
|
printer.Panic(errUnexpected)
|
||||||
}()
|
}()
|
||||||
var times uint32 = 1
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case fname := <-filenameCh:
|
case fname := <-filenameCh:
|
||||||
|
@ -143,7 +147,7 @@ func runAndWatch(flags cli.Flags) error {
|
||||||
fname = " " // we don't want to print the ".gooutput..." so dont print anything as a name
|
fname = " " // we don't want to print the ".gooutput..." so dont print anything as a name
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.Infof("\n[OP: %d] File %s changed, reloading...", atomic.LoadUint32(×), fname)
|
printer.Infof("[OP: %d] File %s changed, reloading...", atomic.LoadUint32(×), fname)
|
||||||
|
|
||||||
//kill the prev run
|
//kill the prev run
|
||||||
|
|
||||||
|
@ -165,13 +169,12 @@ func runAndWatch(flags cli.Flags) error {
|
||||||
printer.Warningf(err.Error())
|
printer.Warningf(err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if runCmd, err = run(executablePath, false); err != nil {
|
if runCmd, err = run(executablePath); err != nil {
|
||||||
printer.Warningf(err.Error())
|
printer.Warningf(err.Error() + "\n")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// we did .Start, but it should be fast so no need to add a sleeper
|
// we did .Start, but it should be fast so no need to add a sleeper
|
||||||
printer.Successf("ready!")
|
printer.Successf("ready!\n")
|
||||||
atomic.AddUint32(×, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user