mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-18 18:58:54 +02:00
no context pointers
This commit is contained in:
@@ -122,7 +122,7 @@ func AddToDbIfNew(db *gorm.DB, entry data.HistoryEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
func getCustomColumnValue(ctx *context.Context, header string, entry data.HistoryEntry) (string, error) {
|
||||
func getCustomColumnValue(ctx context.Context, header string, entry data.HistoryEntry) (string, error) {
|
||||
for _, c := range entry.CustomColumns {
|
||||
if strings.EqualFold(c.Name, header) {
|
||||
return c.Val, nil
|
||||
@@ -137,7 +137,7 @@ func getCustomColumnValue(ctx *context.Context, header string, entry data.Histor
|
||||
return "", fmt.Errorf("failed to find a column matching the column name %#v (is there a typo?)", header)
|
||||
}
|
||||
|
||||
func buildTableRow(ctx *context.Context, columnNames []string, entry data.HistoryEntry) ([]string, error) {
|
||||
func buildTableRow(ctx context.Context, columnNames []string, entry data.HistoryEntry) ([]string, error) {
|
||||
row := make([]string, 0)
|
||||
for _, header := range columnNames {
|
||||
switch header {
|
||||
@@ -179,7 +179,7 @@ func stringArrayToAnyArray(arr []string) []any {
|
||||
return ret
|
||||
}
|
||||
|
||||
func DisplayResults(ctx *context.Context, results []*data.HistoryEntry, numResults int) error {
|
||||
func DisplayResults(ctx context.Context, results []*data.HistoryEntry, numResults int) error {
|
||||
config := hctx.GetConf(ctx)
|
||||
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
|
||||
|
||||
@@ -212,7 +212,7 @@ func DisplayResults(ctx *context.Context, results []*data.HistoryEntry, numResul
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsEnabled(ctx *context.Context) (bool, error) {
|
||||
func IsEnabled(ctx context.Context) (bool, error) {
|
||||
return hctx.GetConf(ctx).IsEnabled, nil
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ func isBashWeirdness(cmd string) bool {
|
||||
return firstCommandBugRegex.MatchString(cmd)
|
||||
}
|
||||
|
||||
func ImportHistory(ctx *context.Context, shouldReadStdin, force bool) (int, error) {
|
||||
func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error) {
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.HaveCompletedInitialImport && !force {
|
||||
// Don't run an import if we already have run one. This avoids importing the same entry multiple times.
|
||||
@@ -404,7 +404,7 @@ func getTmpClientPath() string {
|
||||
return path.Join(tmpDir, "hishtory-client")
|
||||
}
|
||||
|
||||
func Update(ctx *context.Context) error {
|
||||
func Update(ctx context.Context) error {
|
||||
// Download the binary
|
||||
downloadData, err := GetDownloadData()
|
||||
if err != nil {
|
||||
@@ -464,7 +464,7 @@ func Update(ctx *context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifyBinaryMac(ctx *context.Context, binaryPath string, downloadData shared.UpdateInfo) error {
|
||||
func verifyBinaryMac(ctx context.Context, binaryPath string, downloadData shared.UpdateInfo) error {
|
||||
// On Mac, binary verification is a bit more complicated since mac binaries are code
|
||||
// signed. To verify a signed binary, we:
|
||||
// 1. Download the unsigned binary
|
||||
@@ -747,7 +747,7 @@ func EncryptAndMarshal(config hctx.ClientConfig, entries []*data.HistoryEntry) (
|
||||
return jsonValue, nil
|
||||
}
|
||||
|
||||
func Reupload(ctx *context.Context) error {
|
||||
func Reupload(ctx context.Context) error {
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.IsOffline {
|
||||
return nil
|
||||
@@ -769,7 +769,7 @@ func Reupload(ctx *context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RetrieveAdditionalEntriesFromRemote(ctx *context.Context) error {
|
||||
func RetrieveAdditionalEntriesFromRemote(ctx context.Context) error {
|
||||
db := hctx.GetDb(ctx)
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.IsOffline {
|
||||
@@ -797,7 +797,7 @@ func RetrieveAdditionalEntriesFromRemote(ctx *context.Context) error {
|
||||
return ProcessDeletionRequests(ctx)
|
||||
}
|
||||
|
||||
func ProcessDeletionRequests(ctx *context.Context) error {
|
||||
func ProcessDeletionRequests(ctx context.Context) error {
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.IsOffline {
|
||||
return nil
|
||||
@@ -826,7 +826,7 @@ func ProcessDeletionRequests(ctx *context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetBanner(ctx *context.Context) ([]byte, error) {
|
||||
func GetBanner(ctx context.Context) ([]byte, error) {
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.IsOffline {
|
||||
return []byte{}, nil
|
||||
@@ -840,7 +840,7 @@ func parseTimeGenerously(input string) (time.Time, error) {
|
||||
return dateparse.ParseLocal(input)
|
||||
}
|
||||
|
||||
func MakeWhereQueryFromSearch(ctx *context.Context, db *gorm.DB, query string) (*gorm.DB, error) {
|
||||
func MakeWhereQueryFromSearch(ctx context.Context, db *gorm.DB, query string) (*gorm.DB, error) {
|
||||
tokens, err := tokenize(query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to tokenize query: %v", err)
|
||||
@@ -883,7 +883,7 @@ func MakeWhereQueryFromSearch(ctx *context.Context, db *gorm.DB, query string) (
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func Search(ctx *context.Context, db *gorm.DB, query string, limit int) ([]*data.HistoryEntry, error) {
|
||||
func Search(ctx context.Context, db *gorm.DB, query string, limit int) ([]*data.HistoryEntry, error) {
|
||||
if ctx == nil && query != "" {
|
||||
return nil, fmt.Errorf("lib.Search called with a nil context and a non-empty query (this should never happen)")
|
||||
}
|
||||
@@ -913,7 +913,7 @@ func parseNonAtomizedToken(token string) (string, interface{}, interface{}, inte
|
||||
return "(command LIKE ? OR hostname LIKE ? OR current_working_directory LIKE ?)", wildcardedToken, wildcardedToken, wildcardedToken, nil
|
||||
}
|
||||
|
||||
func parseAtomizedToken(ctx *context.Context, token string) (string, interface{}, interface{}, error) {
|
||||
func parseAtomizedToken(ctx context.Context, token string) (string, interface{}, interface{}, error) {
|
||||
splitToken := splitEscaped(token, ':', 2)
|
||||
field := unescape(splitToken[0])
|
||||
val := unescape(splitToken[1])
|
||||
@@ -978,7 +978,7 @@ func parseAtomizedToken(ctx *context.Context, token string) (string, interface{}
|
||||
}
|
||||
}
|
||||
|
||||
func getAllCustomColumnNames(ctx *context.Context) ([]string, error) {
|
||||
func getAllCustomColumnNames(ctx context.Context) ([]string, error) {
|
||||
db := hctx.GetDb(ctx)
|
||||
query := `
|
||||
SELECT DISTINCT json_extract(value, '$.name') as cc_name
|
||||
|
Reference in New Issue
Block a user