Entry point for parsing theme metadata
This commit is contained in:
parent
8ba7258db9
commit
3eb18a416a
@ -3,7 +3,10 @@
|
|||||||
package themes
|
package themes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -96,3 +99,45 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
|
|||||||
func EntryPoint(parent *cli.Command) {
|
func EntryPoint(parent *cli.Command) {
|
||||||
create_cmd(parent, main)
|
create_cmd(parent, main)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parse_theme_metadata() error {
|
||||||
|
raw, err := io.ReadAll(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
paths := utils.Splitlines(utils.UnsafeBytesToString(raw))
|
||||||
|
ans := make([]*themes.ThemeMetadata, 0, len(paths))
|
||||||
|
for _, path := range paths {
|
||||||
|
if path != "" {
|
||||||
|
metadata, _, err := themes.ParseThemeMetadata(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ans = append(ans, metadata)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw, err = json.Marshal(ans)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = os.Stdout.Write(raw)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseEntryPoint(parent *cli.Command) {
|
||||||
|
parent.AddSubCommand(&cli.Command{
|
||||||
|
Name: "__parse_theme_metadata__",
|
||||||
|
Hidden: true,
|
||||||
|
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
|
||||||
|
err = parse_theme_metadata()
|
||||||
|
if err != nil {
|
||||||
|
rc = 1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -54,6 +54,7 @@ func KittyToolEntryPoints(root *cli.Command) {
|
|||||||
diff.EntryPoint(root)
|
diff.EntryPoint(root)
|
||||||
// themes
|
// themes
|
||||||
themes.EntryPoint(root)
|
themes.EntryPoint(root)
|
||||||
|
themes.ParseEntryPoint(root)
|
||||||
// __pytest__
|
// __pytest__
|
||||||
pytest.EntryPoint(root)
|
pytest.EntryPoint(root)
|
||||||
// __hold_till_enter__
|
// __hold_till_enter__
|
||||||
|
|||||||
@ -463,7 +463,7 @@ type ThemeMetadata struct {
|
|||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse_theme_metadata(path string) (*ThemeMetadata, map[string]string, error) {
|
func ParseThemeMetadata(path string) (*ThemeMetadata, map[string]string, error) {
|
||||||
var in_metadata, in_blurb, finished_metadata bool
|
var in_metadata, in_blurb, finished_metadata bool
|
||||||
ans := ThemeMetadata{}
|
ans := ThemeMetadata{}
|
||||||
settings := map[string]string{}
|
settings := map[string]string{}
|
||||||
@ -816,7 +816,7 @@ func (self *Themes) Filtered(is_ok func(*Theme) bool) *Themes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Themes) AddFromFile(path string) (*Theme, error) {
|
func (self *Themes) AddFromFile(path string) (*Theme, error) {
|
||||||
m, conf, err := parse_theme_metadata(path)
|
m, conf, err := ParseThemeMetadata(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user