mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 15:10:35 +03:00
parent
1e233b1c45
commit
a7d00fc39e
3 changed files with 72 additions and 3 deletions
|
@ -39,6 +39,11 @@ import (
|
|||
)
|
||||
|
||||
type serverCmd struct {
|
||||
// Can be used to stop the server. Useful in tests
|
||||
stop <-chan bool
|
||||
// Can be used to receive notification about when the server is started. Useful in tests.
|
||||
started chan<- bool
|
||||
|
||||
disableLiveReload bool
|
||||
navigateToChanged bool
|
||||
renderToDisk bool
|
||||
|
@ -55,7 +60,11 @@ type serverCmd struct {
|
|||
}
|
||||
|
||||
func newServerCmd() *serverCmd {
|
||||
cc := &serverCmd{}
|
||||
return newServerCmdSignaled(nil, nil)
|
||||
}
|
||||
|
||||
func newServerCmdSignaled(stop <-chan bool, started chan<- bool) *serverCmd {
|
||||
cc := &serverCmd{stop: stop, started: started}
|
||||
|
||||
cc.baseBuilderCmd = newBuilderCmd(&cobra.Command{
|
||||
Use: "server",
|
||||
|
@ -394,9 +403,20 @@ func (c *commandeer) serve(s *serverCmd) error {
|
|||
}()
|
||||
}
|
||||
|
||||
if s.started != nil {
|
||||
s.started <- true
|
||||
}
|
||||
|
||||
jww.FEEDBACK.Println("Press Ctrl+C to stop")
|
||||
|
||||
<-sigs
|
||||
if s.stop != nil {
|
||||
select {
|
||||
case <-sigs:
|
||||
case <-s.stop:
|
||||
}
|
||||
} else {
|
||||
<-sigs
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue