12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package main
- import (
- "fmt"
- se "git.swzry.com/ProjectNagae/saki-v0/engine"
- "github.com/BurntSushi/toml"
- "github.com/urfave/cli/v2"
- "os"
- )
- var _ se.Config = (*Config)(nil)
- type TomlConfigDef struct {
- VmConfig *VmConfigDef `toml:"vm"`
- }
- type Config struct {
- *TomlConfigDef
- willPrintResults bool
- isStrictMode bool
- suppressWarning bool
- }
- func (c *Config) RuntimeWarning(err error) {
- if !c.suppressWarning {
- RuntimeWarning(err)
- }
- }
- func (c *Config) IsStrictMode() bool {
- return c.isStrictMode
- }
- func (c *Config) WillPrintResults() bool {
- return c.willPrintResults
- }
- func (c *Config) SetArgsSpecifiedItemsForExec(cx *cli.Context) {
- strictMode := cx.Bool("strict-mode")
- noResultPrint := cx.Bool("no-js-result-print")
- suppressWarning := cx.Bool("suppress-warn")
- c.isStrictMode = strictMode
- c.willPrintResults = !noResultPrint
- c.suppressWarning = suppressWarning
- }
- func (c *TomlConfigDef) GlobalModulePath() []string {
- return c.VmConfig.GlobalModuleFolders
- }
- type VmConfigDef struct {
- GlobalModuleFolders []string `toml:"global_module_folders"`
- }
- func LoadConfig(c *cli.Context) (*Config, error) {
- cfgFile := c.String("config")
- if cfgFile == "" {
- cfgFile = "/nagae/elip4ng/config/sakish.toml"
- }
- cfgBin, err := os.ReadFile(cfgFile)
- if err != nil {
- return nil, fmt.Errorf("failed to read config file at %s:\n%w", cfgFile, err)
- }
- var tcfg *TomlConfigDef
- err = toml.Unmarshal(cfgBin, &tcfg)
- if err != nil {
- return nil, fmt.Errorf("failed to parse config file at %s:\n%w", cfgFile, err)
- }
- cfg := Config{
- TomlConfigDef: tcfg,
- }
- return &cfg, nil
- }
|