You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zk/internal/core/notebook_path.go

33 lines
853 B
Go

package core
import "path/filepath"
type NotebookPath struct {
// Path of a notebook file, relative to the notebook dir.
Path string
// Root directory of the notebook.
BasePath string
// Current working directory.
WorkingDir string
}
// Filename returns the filename of the notebook file.
func (p NotebookPath) Filename() string {
return filepath.Base(p.Path)
}
// AbsPath returns the absolute path to the notebook file.
func (p NotebookPath) AbsPath() string {
return filepath.Join(p.BasePath, p.Path)
}
// PathRelToWorkingDir returns the path to the notebook file relative to the
// working dir. If the working dir is not set, returns the path relative to the
// notebook dir.
func (p NotebookPath) PathRelToWorkingDir() (string, error) {
if p.WorkingDir == "" {
return p.Path, nil
}
return filepath.Rel(p.WorkingDir, p.AbsPath())
}