Created
January 31, 2017 00:14
-
-
Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.
Program for testing programs that launch other programs. Dawg.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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