backstack: added saving of backstack to workspace
This commit is contained in:
parent
96207821a2
commit
721d3abe5e
9 changed files with 214 additions and 11 deletions
37
internal/common/workspaces/manager.go
Normal file
37
internal/common/workspaces/manager.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package workspaces
|
||||
|
||||
import (
|
||||
"github.com/asdine/storm"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type MetaInfo struct {
|
||||
Command string
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
metainfo MetaInfo
|
||||
}
|
||||
|
||||
func New(metaInfo MetaInfo) *Manager {
|
||||
return &Manager{metainfo: metaInfo}
|
||||
}
|
||||
|
||||
func (m *Manager) Open(filename string) (*Workspace, error) {
|
||||
db, err := storm.Open(filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot open workspace at %v", filename)
|
||||
}
|
||||
return &Workspace{db: db}, nil
|
||||
}
|
||||
|
||||
func (m *Manager) CreateTemp() (*Workspace, error) {
|
||||
workspaceFile, err := os.CreateTemp("", m.metainfo.Command+"*.workspace")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot create workspace file")
|
||||
}
|
||||
workspaceFile.Close() // We just need the filename
|
||||
|
||||
return m.Open(workspaceFile.Name())
|
||||
}
|
||||
19
internal/common/workspaces/workspaces.go
Normal file
19
internal/common/workspaces/workspaces.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package workspaces
|
||||
|
||||
import (
|
||||
"github.com/asdine/storm"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Workspace struct {
|
||||
db *storm.DB
|
||||
}
|
||||
|
||||
func (ws *Workspace) DB() *storm.DB {
|
||||
return ws.db
|
||||
}
|
||||
|
||||
func (ws *Workspace) Close() {
|
||||
log.Printf("close workspace")
|
||||
ws.db.Close()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue