66 "os"
77 "strings"
88
9+ "github.com/shirou/gopsutil/v4/disk"
910 "github.com/shirou/gopsutil/v4/sensors"
1011)
1112
@@ -18,11 +19,13 @@ const (
1819 cliIntentConfigPrint
1920 cliIntentDiagnose
2021 cliIntentSensorsPrint
22+ cliIntentMountpointInfo
2123)
2224
2325type cliOptions struct {
2426 intent cliIntent
2527 configPath string
28+ args []string
2629}
2730
2831func parseCliOptions () (* cliOptions , error ) {
@@ -46,6 +49,7 @@ func parseCliOptions() (*cliOptions, error) {
4649 fmt .Println (" config:validate Validate the config file" )
4750 fmt .Println (" config:print Print the parsed config file with embedded includes" )
4851 fmt .Println (" sensors:print List all sensors" )
52+ fmt .Println (" mountpoint:info Print information about a given mountpoint path" )
4953 fmt .Println (" diagnose Run diagnostic checks" )
5054 }
5155 configPath := flags .String ("config" , "glance.yml" , "Set config path" )
@@ -72,13 +76,20 @@ func parseCliOptions() (*cliOptions, error) {
7276 } else {
7377 return nil , unknownCommandErr
7478 }
79+ } else if len (args ) == 2 {
80+ if args [0 ] == "mountpoint:info" {
81+ intent = cliIntentMountpointInfo
82+ } else {
83+ return nil , unknownCommandErr
84+ }
7585 } else {
7686 return nil , unknownCommandErr
7787 }
7888
7989 return & cliOptions {
8090 intent : intent ,
8191 configPath : * configPath ,
92+ args : args ,
8293 }, nil
8394}
8495
@@ -106,3 +117,23 @@ func cliSensorsPrint() int {
106117
107118 return 0
108119}
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