Skip to content

Commit

Permalink
refactor: rename read file closure
Browse files Browse the repository at this point in the history
  • Loading branch information
tshakalekholoane committed Jun 28, 2023
1 parent cd24e16 commit ca6b9e0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
}

first := batteries[0]
read := func(v string) string {
mustRead := func(v string) string {
data, err := os.ReadFile(filepath.Join(first, v))
if err != nil {
log.Fatal(err)
Expand All @@ -82,7 +82,7 @@ func main() {
case "-v", "--version":
fmt.Fprintf(os.Stdout, version, tag, time.Now().Year())
case "capacity", "status":
fmt.Fprint(os.Stdout, read(option))
fmt.Fprint(os.Stdout, mustRead(option))
case "persist":
output, err := exec.Command("systemctl", "--version").CombinedOutput()
if err != nil {
Expand All @@ -101,7 +101,7 @@ func main() {
os.Exit(1)
}

current, err := strconv.Atoi(strings.TrimSpace(read(threshold)))
current, err := strconv.Atoi(strings.TrimSpace(mustRead(threshold)))
if err != nil {
log.Fatal(err)
}
Expand All @@ -122,7 +122,7 @@ func main() {
fmt.Fprintln(os.Stdout, "Persistence of the current charging threshold enabled.")
case "threshold":
if len(os.Args) < 3 {
fmt.Fprint(os.Stdout, read(threshold))
fmt.Fprint(os.Stdout, mustRead(threshold))
} else {
t := os.Args[2]
v, err := strconv.Atoi(t)
Expand Down

0 comments on commit ca6b9e0

Please sign in to comment.