Porovnat revize

...

2 Commity

Autor SHA1 Zpráva Datum
e63ad28f74 Print usage also when an invalid command is supplied 2021-03-22 19:51:29 +01:00
eb0612864d search: concat multiple arguments. Don't just use the first
This is more natural
2021-03-22 19:49:44 +01:00

13
main.go
Zobrazit soubor

@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
_ "modernc.org/sqlite"
)
@ -118,6 +119,10 @@ func exists(path string) (bool, error) {
return false, err
}
func printUsage() {
fmt.Fprintf(os.Stderr, "Usage: ./hs9001 <add/search/init/import>\n")
}
func main() {
var ret int
flag.IntVar(&ret, "ret", 0, "Return value of the command to add")
@ -126,7 +131,7 @@ func main() {
argslen := len(args)
if argslen < 1 {
fmt.Fprintf(os.Stderr, "Usage: ./hs9001 <add/search/init/import>\n")
printUsage()
return
}
@ -152,7 +157,7 @@ func main() {
if argslen < 2 {
fmt.Fprint(os.Stderr, "Please provide the search query\n")
}
q := args[1]
q := strings.Join(args[1:], " ")
search(conn, q)
os.Exit(23)
} else if cmd == "init" {
@ -163,5 +168,9 @@ func main() {
initDatabase(conn)
} else if cmd == "import" {
importFromStdin(conn)
} else {
fmt.Fprint(os.Stderr, "Error: Unknown command supplied\n\n")
printUsage()
return
}
}