Skip to content

Commit

Permalink
record last edit time whenever db changes are made
Browse files Browse the repository at this point in the history
  • Loading branch information
theredditbandit committed May 21, 2024
1 parent 914be59 commit 62794de
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"errors"
"fmt"
"log"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -42,7 +44,13 @@ avlpn or something smaller and use that to query pman`,
if err != nil {
return err
}

lastEdit := make(map[string]string)
lastEdit["lastWrite"] = fmt.Sprintf(time.Now().Format("02 Jan 06 15:04"))
err = db.WriteToDB(db.DBName, lastEdit, ConfigBucket)
if err != nil {
log.Print(err)
return err
}
return nil
},
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"errors"
"fmt"
"log"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -52,6 +54,13 @@ var delCmd = &cobra.Command{
if err != nil {
return err
}
lastEdit := make(map[string]string)
lastEdit["lastWrite"] = fmt.Sprintf(time.Now().Format("02 Jan 06 15:04"))
err = db.WriteToDB(db.DBName, lastEdit, ConfigBucket)
if err != nil {
log.Print(err)
return err
}
fmt.Printf("Successfully deleted %s from the db \n", projName)
return nil
},
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
StatusBucket = "projects"
ProjectPathBucket = "projectPaths"
ProjectAliasBucket = "projectAliases"
ConfigBucket = "config"
version = "1.0"
)

Expand Down
11 changes: 11 additions & 0 deletions cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"errors"
"fmt"
"log"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -47,6 +49,15 @@ var setCmd = &cobra.Command{
fmt.Println("Error updating record : ", err)
return err
}

lastEdit := make(map[string]string)
lastEdit["lastWrite"] = fmt.Sprintf(time.Now().Format("02 Jan 06 15:04"))
err = db.WriteToDB(db.DBName, lastEdit, ConfigBucket)
if err != nil {
log.Print(err)
return err
}

fmt.Printf("Project %s set to status %s\n", pname, status)
return nil
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package pkg

import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"time"

"github.com/theredditbandit/pman/pkg/db"
)
Expand All @@ -14,6 +16,7 @@ const (
ProjectPaths = "projectPaths"
ProjectAliasBucket = "projectAliases"
LastUpdatedBucket = "lastUpdated"
ConfigBucket = "config"
)

var (
Expand Down Expand Up @@ -61,6 +64,14 @@ func InitDirs(args []string) error {
log.Print(err)
return err
}
lastEdit := make(map[string]string)
lastEdit["lastWrite"] = fmt.Sprintf(time.Now().Format("02 Jan 06 15:04"))
err = db.WriteToDB(db.DBName, lastEdit, ConfigBucket)
if err != nil {
log.Print(err)
return err
}

return nil
}

Expand Down

0 comments on commit 62794de

Please sign in to comment.