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
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
@ -78,6 +79,14 @@ type Framework struct {
|
|||
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.
|
||||
//
|
||||
// Receives an optional config.Iris as parameter
|
||||
|
@ -161,7 +170,9 @@ func (s *Framework) openServer() (err error) {
|
|||
s.HTTPServer.SetHandler(s.mux)
|
||||
if err = s.HTTPServer.Open(); err == nil {
|
||||
// print the banner
|
||||
if !s.Config.DisableBanner {
|
||||
if s.Config.DisableBanner || SkipBannerFlag {
|
||||
// skip the banner
|
||||
} else {
|
||||
s.Logger.PrintBanner(banner,
|
||||
fmt.Sprintf("%s: Running at %s\n", time.Now().Format(config.TimeFormat),
|
||||
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)
|
||||
|
||||
## Install
|
||||
Current version: 0.0.7
|
||||
Current version: 0.0.8
|
||||
```sh
|
||||
|
||||
go get -u github.com/kataras/iris/iris
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "0.0.7"
|
||||
Version = "0.0.8"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
25
iris/run.go
25
iris/run.go
|
@ -23,6 +23,8 @@ var (
|
|||
goExt = ".go"
|
||||
)
|
||||
|
||||
var times uint32 = 0
|
||||
|
||||
func build(sourcepath string) error {
|
||||
goBuild := utils.CommandBuilder("go", "build", sourcepath)
|
||||
goBuild.Dir = workingDir
|
||||
|
@ -36,13 +38,14 @@ func build(sourcepath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func run(executablePath string, stdout bool) (*utils.Cmd, error) {
|
||||
func run(executablePath string) (*utils.Cmd, error) {
|
||||
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.Stderr = os.Stderr
|
||||
if stdout {
|
||||
runCmd.Stdout = os.Stdout
|
||||
}
|
||||
runCmd.Stdout = os.Stdout
|
||||
|
||||
runCmd.Stderr = os.Stderr
|
||||
if err := runCmd.Start(); err != nil {
|
||||
|
@ -50,6 +53,7 @@ func run(executablePath string, stdout bool) (*utils.Cmd, error) {
|
|||
printer.Dangerf(ferr.Error())
|
||||
return nil, ferr
|
||||
}
|
||||
times++
|
||||
return runCmd, nil
|
||||
}
|
||||
|
||||
|
@ -122,7 +126,7 @@ func runAndWatch(flags cli.Flags) error {
|
|||
return err
|
||||
}
|
||||
|
||||
runCmd, err := run(executablePath, true)
|
||||
runCmd, err := run(executablePath)
|
||||
|
||||
if err != nil {
|
||||
printer.Dangerf(err.Error())
|
||||
|
@ -133,7 +137,7 @@ func runAndWatch(flags cli.Flags) error {
|
|||
printer.Dangerf("")
|
||||
printer.Panic(errUnexpected)
|
||||
}()
|
||||
var times uint32 = 1
|
||||
|
||||
for {
|
||||
select {
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
@ -165,13 +169,12 @@ func runAndWatch(flags cli.Flags) error {
|
|||
printer.Warningf(err.Error())
|
||||
} else {
|
||||
|
||||
if runCmd, err = run(executablePath, false); err != nil {
|
||||
printer.Warningf(err.Error())
|
||||
if runCmd, err = run(executablePath); err != nil {
|
||||
printer.Warningf(err.Error() + "\n")
|
||||
|
||||
} else {
|
||||
// we did .Start, but it should be fast so no need to add a sleeper
|
||||
printer.Successf("ready!")
|
||||
atomic.AddUint32(×, 1)
|
||||
printer.Successf("ready!\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user