Skip to content

Commit d017e83

Browse files
authored
Merge pull request #11 from edoardottt/devel
Make a cli tool of it #10
2 parents 6b86a06 + 9e62271 commit d017e83

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ Install 📡
2929
----------
3030

3131
```console
32-
go get github.com/edoardottt/go-readingtime
32+
go install github.com/edoardottt/go-readingtime/cmd/readt@latest
3333
```
3434

3535
Usage 💡
3636
----------
3737

38+
CLI tool
39+
40+
```console
41+
readt <filepath>
42+
```
43+
44+
Golang module
45+
3846
```go
3947
package main
4048

cmd/readt/readt.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
8+
reading "github.com/edoardottt/go-readingtime"
9+
)
10+
11+
const (
12+
argsNumber = 2
13+
)
14+
15+
func main() {
16+
if len(os.Args) != argsNumber {
17+
log.Fatal("Usage: readt filepath")
18+
}
19+
20+
file, err := os.ReadFile(os.Args[1])
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
25+
t := reading.HumanEstimate(string(file))
26+
27+
fmt.Printf("It would take about %s.\n", t)
28+
}

0 commit comments

Comments
 (0)