2022-01-09 06:59:28 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-01-09 23:34:59 +01:00
|
|
|
"fmt"
|
2022-01-09 06:59:28 +01:00
|
|
|
"os"
|
2022-01-09 20:00:53 +01:00
|
|
|
"strings"
|
2022-01-09 06:59:28 +01:00
|
|
|
|
|
|
|
"github.com/ddworken/hishtory/shared"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-01-10 00:48:20 +01:00
|
|
|
if len(os.Args) == 1 {
|
|
|
|
fmt.Println("Must specify a command! Do you mean `hishtory query`?")
|
|
|
|
return
|
|
|
|
}
|
2022-01-09 06:59:28 +01:00
|
|
|
switch os.Args[1] {
|
|
|
|
case "saveHistoryEntry":
|
|
|
|
saveHistoryEntry()
|
|
|
|
case "query":
|
2022-01-10 00:48:20 +01:00
|
|
|
query(strings.Join(os.Args[2:], " "))
|
2022-01-09 06:59:28 +01:00
|
|
|
case "init":
|
2022-01-09 20:00:53 +01:00
|
|
|
shared.CheckFatalError(shared.Setup(os.Args))
|
2022-01-10 00:48:20 +01:00
|
|
|
case "install":
|
|
|
|
shared.CheckFatalError(shared.Install())
|
2022-01-09 20:00:53 +01:00
|
|
|
case "enable":
|
|
|
|
shared.CheckFatalError(shared.Enable())
|
|
|
|
case "disable":
|
|
|
|
shared.CheckFatalError(shared.Disable())
|
2022-01-09 23:34:59 +01:00
|
|
|
default:
|
|
|
|
shared.CheckFatalError(fmt.Errorf("unknown command: %s", os.Args[1]))
|
2022-01-09 06:59:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getServerHostname() string {
|
|
|
|
if server := os.Getenv("HISHTORY_SERVER"); server != "" {
|
|
|
|
return server
|
|
|
|
}
|
|
|
|
return "http://localhost:8080"
|
|
|
|
}
|
|
|
|
|
2022-01-10 00:48:20 +01:00
|
|
|
func query(query string) {
|
2022-01-09 20:00:53 +01:00
|
|
|
userSecret, err := shared.GetUserSecret()
|
|
|
|
shared.CheckFatalError(err)
|
|
|
|
db, err := shared.OpenDB()
|
|
|
|
shared.CheckFatalError(err)
|
2022-01-09 23:34:59 +01:00
|
|
|
data, err := shared.Search(db, userSecret, query, 25)
|
2022-01-09 20:00:53 +01:00
|
|
|
shared.CheckFatalError(err)
|
2022-01-09 23:34:59 +01:00
|
|
|
shared.DisplayResults(data, false)
|
2022-01-09 06:59:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func saveHistoryEntry() {
|
2022-01-09 20:00:53 +01:00
|
|
|
isEnabled, err := shared.IsEnabled()
|
|
|
|
shared.CheckFatalError(err)
|
|
|
|
if !isEnabled {
|
|
|
|
return
|
2022-01-09 06:59:28 +01:00
|
|
|
}
|
2022-01-09 20:00:53 +01:00
|
|
|
entry, err := shared.BuildHistoryEntry(os.Args)
|
|
|
|
shared.CheckFatalError(err)
|
2022-01-09 06:59:28 +01:00
|
|
|
err = shared.Persist(*entry)
|
2022-01-09 20:00:53 +01:00
|
|
|
shared.CheckFatalError(err)
|
2022-01-09 06:59:28 +01:00
|
|
|
}
|