95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
)
|
|
|
|
func parseArgs() {
|
|
var dmin bool
|
|
for i := 1; i < len(os.Args); i++ {
|
|
arg := os.Args[i]
|
|
if arg[0] == '-' {
|
|
switch arg {
|
|
case "-h":
|
|
fmt.Println("Usage:", os.Args[0], "[-h] [-v] [-x] [-n] [-s] [-d <size>] [-t <threads>] [-k <top>] <dir>")
|
|
fmt.Println("Options:")
|
|
fmt.Println(" -h Show this help message")
|
|
fmt.Println(" -v Verbose")
|
|
fmt.Println(" -x Scan current filesystem only")
|
|
fmt.Println(" -n Non-interactive")
|
|
fmt.Println(" -s Silent mode (no output)")
|
|
fmt.Println(" -d Minimum dir size (default: 10M)")
|
|
fmt.Println(" -t Max threads")
|
|
fmt.Println(" -k Top N output results (default: 8)")
|
|
os.Exit(0)
|
|
case "-x":
|
|
config.fsOnly = true
|
|
case "-v":
|
|
config.verbose = true
|
|
case "-vv":
|
|
config.verbose = true
|
|
config.vverbose = true
|
|
case "-n":
|
|
config.noninter = true
|
|
config.silent = false
|
|
case "-s":
|
|
config.silent = true
|
|
config.noninter = false
|
|
config.verbose = false
|
|
config.vverbose = false
|
|
case "-d":
|
|
if i+1 < len(os.Args) {
|
|
config.dmin = sizeRevConv(os.Args[i+1])
|
|
dmin = true
|
|
} else {
|
|
fmt.Println("Missing argument for -d")
|
|
os.Exit(1)
|
|
}
|
|
i++
|
|
case "-t":
|
|
if i+1 < len(os.Args) {
|
|
config.threads = atoi(os.Args[i+1])
|
|
} else {
|
|
fmt.Println("Missing argument for -t")
|
|
os.Exit(1)
|
|
}
|
|
i++
|
|
case "-k":
|
|
if i+1 < len(os.Args) {
|
|
if os.Args[i+1][len(os.Args[i+1])-1] == '%' {
|
|
config.top = int(atoi(os.Args[i+1][:len(os.Args[i+1])-1]))
|
|
} else {
|
|
config.top = int(atoi(os.Args[i+1]))
|
|
}
|
|
} else {
|
|
fmt.Println("Missing argument for -t")
|
|
os.Exit(1)
|
|
}
|
|
i++
|
|
default:
|
|
fmt.Println("Unknown option:", arg)
|
|
os.Exit(1)
|
|
}
|
|
} else {
|
|
config.dir = arg
|
|
}
|
|
}
|
|
if config.dir == "" {
|
|
config.dir = "."
|
|
}
|
|
if config.dir[len(config.dir)-1] == '/' && config.dir != "/" {
|
|
config.dir = config.dir[:len(config.dir)-1]
|
|
}
|
|
if config.dmin == 0 && !dmin {
|
|
config.dmin = sizeRevConv("10M")
|
|
}
|
|
if config.threads == 0 {
|
|
config.threads = runtime.NumCPU()
|
|
}
|
|
if config.top == 0 {
|
|
config.top = 8
|
|
}
|
|
}
|