6
6
"os"
7
7
"strings"
8
8
9
+ "github.com/shirou/gopsutil/v4/disk"
9
10
"github.com/shirou/gopsutil/v4/sensors"
10
11
)
11
12
@@ -18,11 +19,13 @@ const (
18
19
cliIntentConfigPrint
19
20
cliIntentDiagnose
20
21
cliIntentSensorsPrint
22
+ cliIntentMountpointInfo
21
23
)
22
24
23
25
type cliOptions struct {
24
26
intent cliIntent
25
27
configPath string
28
+ args []string
26
29
}
27
30
28
31
func parseCliOptions () (* cliOptions , error ) {
@@ -46,6 +49,7 @@ func parseCliOptions() (*cliOptions, error) {
46
49
fmt .Println (" config:validate Validate the config file" )
47
50
fmt .Println (" config:print Print the parsed config file with embedded includes" )
48
51
fmt .Println (" sensors:print List all sensors" )
52
+ fmt .Println (" mountpoint:info Print information about a given mountpoint path" )
49
53
fmt .Println (" diagnose Run diagnostic checks" )
50
54
}
51
55
configPath := flags .String ("config" , "glance.yml" , "Set config path" )
@@ -72,13 +76,20 @@ func parseCliOptions() (*cliOptions, error) {
72
76
} else {
73
77
return nil , unknownCommandErr
74
78
}
79
+ } else if len (args ) == 2 {
80
+ if args [0 ] == "mountpoint:info" {
81
+ intent = cliIntentMountpointInfo
82
+ } else {
83
+ return nil , unknownCommandErr
84
+ }
75
85
} else {
76
86
return nil , unknownCommandErr
77
87
}
78
88
79
89
return & cliOptions {
80
90
intent : intent ,
81
91
configPath : * configPath ,
92
+ args : args ,
82
93
}, nil
83
94
}
84
95
@@ -106,3 +117,23 @@ func cliSensorsPrint() int {
106
117
107
118
return 0
108
119
}
120
+
121
+ func cliMountpointInfo (requestedPath string ) int {
122
+ usage , err := disk .Usage (requestedPath )
123
+ if err != nil {
124
+ fmt .Printf ("Failed to retrieve info for path %s: %v\n " , requestedPath , err )
125
+ if warns , ok := err .(* disk.Warnings ); ok {
126
+ for _ , w := range warns .List {
127
+ fmt .Printf (" - %v\n " , w )
128
+ }
129
+ }
130
+
131
+ return 1
132
+ }
133
+
134
+ fmt .Println ("Path:" , usage .Path )
135
+ fmt .Println ("FS type:" , ternary (usage .Fstype == "" , "unknown" , usage .Fstype ))
136
+ fmt .Printf ("Used percent: %.1f%%" , usage .UsedPercent )
137
+
138
+ return 0
139
+ }
0 commit comments