Use directory as category if not package directory
This commit is contained in:
parent
3189fc9c71
commit
0f8b31f7a6
@ -40,7 +40,8 @@ The information saved in the json file will be used when compiling the songbook.
|
||||
default:
|
||||
log.Fatal("the add command needs exactly 1 parameter")
|
||||
}
|
||||
settings.CreateScore(path)
|
||||
dir, _ := getSettings()
|
||||
settings.CreateScore(path, dir)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -29,9 +28,9 @@ import (
|
||||
// Score represents the settings for a specific score file
|
||||
type Score struct {
|
||||
Name string // The name of the score in the songbook
|
||||
Categories []string `json:"omitempty"` // Categories to which the scores belong
|
||||
Categories []string `json:",omitempty"` // Categories to which the scores belong
|
||||
Path string // The path to the scores (uncompiled) file
|
||||
LastModified time.Time `json:"omitempty"` // Time when the score source was last modified (will be set internally)
|
||||
LastModified time.Time `json:"-"` // Time when the score source was last modified (will be set internally)
|
||||
}
|
||||
|
||||
// FromJSON reads the settings of a score from a JSON file
|
||||
@ -52,18 +51,22 @@ func FromJSON(path string) (*Score, error) {
|
||||
}
|
||||
|
||||
// CreateScore creates a json file for a score given its path
|
||||
func CreateScore(path string) {
|
||||
func CreateScore(path, workDir string) {
|
||||
if filepath.Ext(path) != ".pdf" {
|
||||
log.WithFields(log.Fields{"path": path}).
|
||||
Warning("Unsupported sheet music file")
|
||||
}
|
||||
|
||||
jsonPath := path[:strings.LastIndex(path, ".")]
|
||||
fmt.Println(jsonPath)
|
||||
s := Score{
|
||||
Path: path,
|
||||
Name: filepath.Base(jsonPath),
|
||||
// TODO: Add folder as category when not in main folder
|
||||
}
|
||||
|
||||
if filepath.Dir(path) != workDir {
|
||||
s.Categories = []string{filepath.Base(filepath.Dir(path))}
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(s, "", " ")
|
||||
helpers.Check(err, "Unable to generate valid json")
|
||||
err = ioutil.WriteFile(jsonPath+".json", data, 0644)
|
||||
|
Reference in New Issue
Block a user