fortify: override default usage function
test / test (push) Successful in 23s Details

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-11-05 00:12:31 +09:00
parent 714818c8aa
commit 861bb1274f
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
1 changed files with 11 additions and 12 deletions

23
main.go
View File

@ -35,16 +35,7 @@ func main() {
// not fatal: this program runs as the privileged user // not fatal: this program runs as the privileged user
} }
flag.Parse() flag.CommandLine.Usage = func() {
fmsg.SetVerbose(flagVerbose)
// root check
if os.Geteuid() == 0 {
fmsg.Fatal("this program must not run as root")
panic("unreachable")
}
printHelp := func() {
fmt.Println() fmt.Println()
fmt.Println("Usage:\tfortify [-v] COMMAND [OPTIONS]") fmt.Println("Usage:\tfortify [-v] COMMAND [OPTIONS]")
fmt.Println() fmt.Println()
@ -67,10 +58,18 @@ func main() {
} }
fmt.Println() fmt.Println()
} }
flag.Parse()
fmsg.SetVerbose(flagVerbose)
// root check
if os.Geteuid() == 0 {
fmsg.Fatal("this program must not run as root")
panic("unreachable")
}
args := flag.Args() args := flag.Args()
if len(args) == 0 { if len(args) == 0 {
printHelp() flag.CommandLine.Usage()
fmsg.Exit(0) fmsg.Exit(0)
} }
@ -94,7 +93,7 @@ func main() {
} }
fmsg.Exit(0) fmsg.Exit(0)
case "help": // print help message case "help": // print help message
printHelp() flag.CommandLine.Usage()
fmsg.Exit(0) fmsg.Exit(0)
case "ps": // print all state info case "ps": // print all state info
var w *tabwriter.Writer var w *tabwriter.Writer