Skip to content

Instantly share code, notes, and snippets.

@adamryman
Created January 31, 2017 00:14
Show Gist options
  • Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.
Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.
Program for testing programs that launch other programs. Dawg.
package main
import (
"fmt"
"time"
"github.com/pkg/errors"
flag "github.com/spf13/pflag"
)
const phrase = "Hello, World!"
var (
sleepStr = flag.StringP("time", "t", "1s", "sleep time between printing")
)
func main() {
flag.Parse()
now := time.Now()
sleepTime, err := time.ParseDuration(*sleepStr)
if err != nil {
fmt.Println(errors.Wrap(err, "cannot parse sleep time"))
fmt.Println("Defaulting to one second")
sleepTime = time.Second
}
for {
fmt.Printf("%s; it has been %s since starting\n", phrase, time.Since(now).String())
time.Sleep(sleepTime)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment