feat: switch config json to toml
parent
1b322b7c17
commit
962a4523b9
|
@ -1,84 +0,0 @@
|
|||
{
|
||||
"apps": {
|
||||
"nvim": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/nvim/init.lua",
|
||||
"external": "~/.config/nvim/init.lua"
|
||||
}
|
||||
]
|
||||
},
|
||||
"kitty": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/kitty/kitty.conf",
|
||||
"external": "~/.config/kitty/kitty.conf"
|
||||
},
|
||||
{
|
||||
"internal": "data/kitty/mocha.conf",
|
||||
"external": "~/.config/kitty/mocha.conf"
|
||||
},
|
||||
{
|
||||
"internal": "data/kitty/kitty-dark.icns",
|
||||
"external": "~/.config/kitty/kitty.app.icns"
|
||||
},
|
||||
{
|
||||
"internal": "data/kitty/mocha.conf",
|
||||
"url": "https://raw.githubusercontent.com/catppuccin/kitty/main/mocha.conf"
|
||||
},
|
||||
{
|
||||
"internal": "data/kitty/kitty-dark.icns",
|
||||
"url": "https://github.com/DinkDonk/kitty-icon/blob/main/kitty-dark.icns?raw=true"
|
||||
},
|
||||
{
|
||||
"internal": "data/kitty/kitty-light.icns",
|
||||
"url": "https://github.com/DinkDonk/kitty-icon/blob/main/kitty-light.icns?raw=true"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alacritty": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/alacritty/alacritty.yml",
|
||||
"external": "~/.config/alacritty/alacritty.yml"
|
||||
},
|
||||
{
|
||||
"internal": "data/alacritty/catppuccin-mocha.yml",
|
||||
"external": "~/.config/alacritty/catppuccin-mocha.yml"
|
||||
},
|
||||
{
|
||||
"internal": "data/alacritty/catppuccin-mocha.yml",
|
||||
"url": "https://raw.githubusercontent.com/catppuccin/alacritty/main/catppuccin-mocha.yml"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bat": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/bat",
|
||||
"external": "~/.config/bat"
|
||||
},
|
||||
{
|
||||
"internal": "data/bat/themes/Catppuccin-mocha.tmTheme",
|
||||
"url": "https://raw.githubusercontent.com/catppuccin/bat/main/Catppuccin-mocha.tmTheme"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fd": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/fd/.ignore",
|
||||
"external": "~/.ignore"
|
||||
}
|
||||
]
|
||||
},
|
||||
"zsh": {
|
||||
"paths": [
|
||||
{
|
||||
"internal": "data/zsh/extra-zshrc",
|
||||
"external": "~/.config/zsh/extra-zshrc"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
[[apps.nvim.paths]]
|
||||
internal = "data/nvim/init.lua"
|
||||
external = "~/.config/nvim/init.lua"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/kitty.conf"
|
||||
external = "~/.config/kitty/kitty.conf"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/mocha.conf"
|
||||
external = "~/.config/kitty/mocha.conf"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/kitty-dark.icns"
|
||||
external = "~/.config/kitty/kitty.app.icns"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/mocha.conf"
|
||||
url = "https://raw.githubusercontent.com/catppuccin/kitty/main/mocha.conf"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/kitty-dark.icns"
|
||||
url = "https://github.com/DinkDonk/kitty-icon/blob/main/kitty-dark.icns?raw=true"
|
||||
|
||||
[[apps.kitty.paths]]
|
||||
internal = "data/kitty/kitty-light.icns"
|
||||
url = "https://github.com/DinkDonk/kitty-icon/blob/main/kitty-light.icns?raw=true"
|
||||
|
||||
[[apps.alacritty.paths]]
|
||||
internal = "data/alacritty/alacritty.yml"
|
||||
external = "~/.config/alacritty/alacritty.yml"
|
||||
|
||||
[[apps.alacritty.paths]]
|
||||
internal = "data/alacritty/catppuccin-mocha.yml"
|
||||
external = "~/.config/alacritty/catppuccin-mocha.yml"
|
||||
|
||||
[[apps.alacritty.paths]]
|
||||
internal = "data/alacritty/catppuccin-mocha.yml"
|
||||
url = "https://raw.githubusercontent.com/catppuccin/alacritty/main/catppuccin-mocha.yml"
|
||||
|
||||
[[apps.bat.paths]]
|
||||
internal = "data/bat"
|
||||
external = "~/.config/bat"
|
||||
|
||||
[[apps.bat.paths]]
|
||||
internal = "data/bat/themes/Catppuccin-mocha.tmTheme"
|
||||
url = "https://raw.githubusercontent.com/catppuccin/bat/main/Catppuccin-mocha.tmTheme"
|
||||
|
||||
[[apps.fd.paths]]
|
||||
internal = "data/fd/.ignore"
|
||||
external = "~/.ignore"
|
||||
|
||||
[[apps.zsh.paths]]
|
||||
internal = "data/zsh/extra-zshrc"
|
||||
external = "~/.config/zsh/extra-zshrc"
|
|
@ -101,12 +101,13 @@ func (a *action) runValidate(c *cli.Context) error {
|
|||
|
||||
func (a *action) loadConfig(c *cli.Context, command string) (config.Config, error) {
|
||||
a.getFlags(c)
|
||||
a.log("start %s with flags %+v\n", command, a.flags)
|
||||
a.log("Start command [%s] with flags [%+v]\n", command, a.flags)
|
||||
|
||||
cfgReal, cfgDemo, err := config.LoadConfig(currentDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("config: failed to load: %w", err)
|
||||
}
|
||||
a.log("Config apps [%+v]\n", cfgReal.Apps)
|
||||
|
||||
if a.flags.dryRun {
|
||||
return cfgDemo, nil
|
||||
|
|
|
@ -167,7 +167,7 @@ func NewApp() *App {
|
|||
func (a *App) Run() {
|
||||
// Prevent running at runtime
|
||||
if _, ok := denyOSes[runtime.GOOS]; ok {
|
||||
color.PrintAppError(appName, fmt.Sprintf("OS %s is not supported right now", runtime.GOOS))
|
||||
color.PrintAppError(appName, fmt.Sprintf("OS [%s] is not supported right now", runtime.GOOS))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ type Path struct {
|
|||
}
|
||||
|
||||
// LoadConfig return config, configDemo
|
||||
func LoadConfig(path string) (*configReal, *configDemo, error) {
|
||||
func LoadConfig(path string) (*ConfigReal, *ConfigDemo, error) {
|
||||
cfgReal, cfgDemo, err := loadConfigJSON(path)
|
||||
if err == nil {
|
||||
return cfgReal, cfgDemo, nil
|
||||
|
@ -59,7 +59,7 @@ func LoadConfig(path string) (*configReal, *configDemo, error) {
|
|||
return nil, nil, ErrConfigNotFound
|
||||
}
|
||||
|
||||
func loadConfigJSON(path string) (*configReal, *configDemo, error) {
|
||||
func loadConfigJSON(path string) (*ConfigReal, *ConfigDemo, error) {
|
||||
configPathJSON := filepath.Join(path, configDirPath, configFileJSON)
|
||||
|
||||
bytes, err := os.ReadFile(configPathJSON)
|
||||
|
@ -72,21 +72,21 @@ func loadConfigJSON(path string) (*configReal, *configDemo, error) {
|
|||
return nil, nil, fmt.Errorf("json: failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
cfgReal := configReal{
|
||||
cfgReal := ConfigReal{
|
||||
httpClient: &http.Client{
|
||||
Timeout: time.Second * 5,
|
||||
},
|
||||
ConfigApps: cfgApps,
|
||||
}
|
||||
|
||||
cfgDemo := configDemo{
|
||||
cfgDemo := ConfigDemo{
|
||||
ConfigApps: cfgApps,
|
||||
}
|
||||
|
||||
return &cfgReal, &cfgDemo, nil
|
||||
}
|
||||
|
||||
func loadConfigTOML(path string) (*configReal, *configDemo, error) {
|
||||
func loadConfigTOML(path string) (*ConfigReal, *ConfigDemo, error) {
|
||||
configPathTOML := filepath.Join(path, configDirPath, configFileTOML)
|
||||
|
||||
bytes, err := os.ReadFile(configPathTOML)
|
||||
|
@ -99,14 +99,14 @@ func loadConfigTOML(path string) (*configReal, *configDemo, error) {
|
|||
return nil, nil, fmt.Errorf("toml: failed to decode: %w", err)
|
||||
}
|
||||
|
||||
cfgReal := configReal{
|
||||
cfgReal := ConfigReal{
|
||||
httpClient: &http.Client{
|
||||
Timeout: time.Second * 5,
|
||||
},
|
||||
ConfigApps: cfgApps,
|
||||
}
|
||||
|
||||
cfgDemo := configDemo{
|
||||
cfgDemo := ConfigDemo{
|
||||
ConfigApps: cfgApps,
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ package config
|
|||
|
||||
import "fmt"
|
||||
|
||||
type configDemo struct {
|
||||
type ConfigDemo struct {
|
||||
ConfigApps
|
||||
}
|
||||
|
||||
var _ Config = (*configDemo)(nil)
|
||||
var _ Config = (*ConfigDemo)(nil)
|
||||
|
||||
func (c *configDemo) Install() error {
|
||||
func (c *ConfigDemo) Install() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.External == "" {
|
||||
|
@ -22,7 +22,7 @@ func (c *configDemo) Install() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configDemo) Update() error {
|
||||
func (c *ConfigDemo) Update() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.External == "" {
|
||||
|
@ -36,7 +36,7 @@ func (c *configDemo) Update() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configDemo) Download() error {
|
||||
func (c *ConfigDemo) Download() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.URL == "" {
|
||||
|
@ -50,7 +50,7 @@ func (c *configDemo) Download() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configDemo) Clean() error {
|
||||
func (c *ConfigDemo) Clean() error {
|
||||
unusedDirs, err := getUnusedDirs(c.Apps)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -63,10 +63,10 @@ func (c *configDemo) Clean() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configDemo) Diff() error {
|
||||
func (c *ConfigDemo) Diff() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *configDemo) Validate() error {
|
||||
func (c *ConfigDemo) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ import (
|
|||
|
||||
var ErrConfigInvalid = errors.New("config invalid")
|
||||
|
||||
type configReal struct {
|
||||
type ConfigReal struct {
|
||||
httpClient *http.Client
|
||||
ConfigApps
|
||||
}
|
||||
|
||||
var _ Config = (*configReal)(nil)
|
||||
var _ Config = (*ConfigReal)(nil)
|
||||
|
||||
// Install internal -> external
|
||||
func (c *configReal) Install() error {
|
||||
func (c *ConfigReal) Install() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.External == "" {
|
||||
|
@ -39,7 +39,7 @@ func (c *configReal) Install() error {
|
|||
}
|
||||
|
||||
// Update external -> internal
|
||||
func (c *configReal) Update() error {
|
||||
func (c *ConfigReal) Update() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.External == "" {
|
||||
|
@ -55,7 +55,7 @@ func (c *configReal) Update() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configReal) Download() error {
|
||||
func (c *ConfigReal) Download() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.URL == "" {
|
||||
|
@ -91,7 +91,7 @@ func (c *configReal) Download() error {
|
|||
}
|
||||
|
||||
// Clean remove unused config inside config dir
|
||||
func (c *configReal) Clean() error {
|
||||
func (c *ConfigReal) Clean() error {
|
||||
unusedDirs, err := getUnusedDirs(c.Apps)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -133,7 +133,7 @@ func getUnusedDirs(apps map[string]App) (map[string]struct{}, error) {
|
|||
return unusedDirs, nil
|
||||
}
|
||||
|
||||
func (c *configReal) Diff() error {
|
||||
func (c *ConfigReal) Diff() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.External == "" {
|
||||
|
@ -149,7 +149,7 @@ func (c *configReal) Diff() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *configReal) Validate() error {
|
||||
func (c *ConfigReal) Validate() error {
|
||||
for _, app := range c.Apps {
|
||||
for _, p := range app.Paths {
|
||||
if p.Internal == "" {
|
||||
|
|
Loading…
Reference in New Issue