diff --git a/README.md b/README.md index 9e36d9f..99f2ff0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ --- -Timer is a small CLI, similar to the `sleep` everyone already knows and love, +Timer is a small CLI, similar to the `sleep` everyone already knows and love, with a couple of extra features: - a progress bar indicating the progression of said timer @@ -22,6 +22,11 @@ man timer timer --help ``` +It is possible to pass a time unit for ``. + +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". +If no unit is passed, it defaults to seconds ("s"). + ## Install **homebrew**: diff --git a/main.go b/main.go index 9318f54..20005a4 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "strconv" "time" "github.com/charmbracelet/bubbles/key" @@ -112,6 +113,7 @@ var rootCmd = &coral.Command{ SilenceUsage: true, Args: coral.ExactArgs(1), RunE: func(cmd *coral.Command, args []string) error { + addSuffixIfArgIsNumber(&(args[0]), "s") duration, err := time.ParseDuration(args[0]) if err != nil { return err @@ -156,3 +158,10 @@ func main() { os.Exit(1) } } + +func addSuffixIfArgIsNumber(s *string, suffix string) { + _, err := strconv.ParseFloat(*s, 64) + if err == nil { + *s = *s + suffix + } +}