diff options
author | Adam Mathes <adam@trenchant.org> | 2017-12-30 08:54:50 -0800 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2017-12-30 08:54:50 -0800 |
commit | 7b0cd305f4bdc8354e1f0de81d5d1b224f854fcb (patch) | |
tree | 683aa86719c05bd1c2f35b1964284c0958395a0a | |
parent | cc59df8acfda58c34d5db14dc1db9eba3390b527 (diff) | |
download | snkt-7b0cd305f4bdc8354e1f0de81d5d1b224f854fcb.tar.gz snkt-7b0cd305f4bdc8354e1f0de81d5d1b224f854fcb.tar.bz2 snkt-7b0cd305f4bdc8354e1f0de81d5d1b224f854fcb.zip |
cleanups to main.go cli
-rw-r--r-- | main.go | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -17,18 +17,18 @@ import ( func main() { var configFile, init_dir string - var build, preview, version, verbose, help, watch bool + var build, serve, version, verbose, help, watch bool flag.StringVarP(&configFile, "config", "c", "config.yml", "`configuration` file") flag.StringVarP(&init_dir, "init", "i", "", "initialize new site at `directory`") flag.BoolVarP(&build, "build", "b", false, "generates site from input files and templates") - flag.BoolVarP(&preview, "preview", "p", false, "preview site via spawned HTTP server") + flag.BoolVarP(&serve, "serve", "s", false, "serve site via integrated HTTP server") flag.BoolVarP(&help, "help", "h", false, "print usage information") flag.BoolVarP(&verbose, "verbose", "v", false, "log operations during build to STDOUT") flag.BoolVarP(&watch, "watch", "w", false, "watch configured input text dir, rebuild on changes") flag.Parse() - if !watch && !help && !build && !preview && !version && init_dir == "" { + if !watch && !help && !build && !serve && !version && init_dir == "" { flag.Usage() return } @@ -53,18 +53,23 @@ func main() { buildSite() } - if preview { - fmt.Printf("spawning preview server [%s] of [%s]\n", + if serve { + fmt.Printf("serving [%s] at [%s]\n", config.Config.PreviewServer, config.Config.PreviewDir) - go func() { - web.Serve(config.Config.PreviewServer, config.Config.PreviewDir) - }() + // run on goroutine so watcher can start and block if needed + go web.Serve(config.Config.PreviewServer, config.Config.PreviewDir) } if watch { - fmt.Printf("watching directory %s\n", config.Config.TxtDir) + fmt.Printf("watching %s\n", config.Config.TxtDir) watchSite() } + + // run preview server perpetually + if serve { + done := make(chan bool) + <-done + } } func buildSite() { |