Commit 1ec2696

Karn Wong <[email protected]>
2024-08-07 06:06:09
feat: add sensors tag: v0.2.0
1 parent 695c74e
Changed files (3)
cmd/get/get_sensors.go
@@ -0,0 +1,36 @@
+package get
+
+import (
+	"fmt"
+
+	"github.com/kahnwong/swissknife/color"
+	"github.com/rs/zerolog/log"
+	"github.com/shirou/gopsutil/v4/sensors"
+	"github.com/spf13/cobra"
+)
+
+var SensorsCmd = &cobra.Command{
+	Use:   "sensors",
+	Short: "Get sensors info",
+	Run: func(cmd *cobra.Command, args []string) {
+		sensors, err := sensors.SensorsTemperatures()
+		if err != nil {
+			log.Fatal().Err(err).Msg("Failed to get sensors info")
+		}
+
+		var temperature float64
+		for _, sensor := range sensors {
+			if sensor.SensorKey == "PMU" {
+				if temperature < sensor.Temperature {
+					temperature = sensor.Temperature
+				}
+			}
+		}
+
+		fmt.Printf("%s: %.2f\n", color.Green("Temperature"), temperature)
+	},
+}
+
+func init() {
+	Cmd.AddCommand(SensorsCmd)
+}
go.mod
@@ -12,7 +12,7 @@ require (
 	github.com/rs/zerolog v1.33.0
 	github.com/sethvargo/go-diceware v0.4.0
 	github.com/sethvargo/go-password v0.3.1
-	github.com/shirou/gopsutil/v4 v4.24.6
+	github.com/shirou/gopsutil/v4 v4.24.7
 	github.com/showwin/speedtest-go v1.7.8
 	github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
 	github.com/spf13/cobra v1.8.1
go.sum
@@ -78,8 +78,8 @@ github.com/sethvargo/go-diceware v0.4.0 h1:T9o5HaG+8Ae6We4LhItjzOSdTkW7hsikNexa5
 github.com/sethvargo/go-diceware v0.4.0/go.mod h1:Lg1SyPS7yQO6BBgTN5r4f2MUDkqGfLWsOjHPY0kA8iw=
 github.com/sethvargo/go-password v0.3.1 h1:WqrLTjo7X6AcVYfC6R7GtSyuUQR9hGyAj/f1PYQZCJU=
 github.com/sethvargo/go-password v0.3.1/go.mod h1:rXofC1zT54N7R8K/h1WDUdkf9BOx5OptoxrMBcrXzvs=
-github.com/shirou/gopsutil/v4 v4.24.6 h1:9qqCSYF2pgOU+t+NgJtp7Co5+5mHF/HyKBUckySQL64=
-github.com/shirou/gopsutil/v4 v4.24.6/go.mod h1:aoebb2vxetJ/yIDZISmduFvVNPHqXQ9SEJwRXxkf0RA=
+github.com/shirou/gopsutil/v4 v4.24.7 h1:V9UGTK4gQ8HvcnPKf6Zt3XHyQq/peaekfxpJ2HSocJk=
+github.com/shirou/gopsutil/v4 v4.24.7/go.mod h1:0uW/073rP7FYLOkvxolUQM5rMOLTNmRXnFKafpb71rw=
 github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
 github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
 github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=