Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +22,11 @@ man timer
timer --help
```

It is possible to pass a time unit for `<duration>`.

Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
If no unit is passed, it defaults to seconds ("s").

## Install

**homebrew**:
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strconv"
"time"

"github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}