Skip to content

Commit

Permalink
Fix accessor of embed path
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Mar 6, 2024
1 parent 2d0f528 commit 77fc9cf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
72 changes: 37 additions & 35 deletions cmd/winit-conf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,7 @@ func (p provisioner) DstPath() string {
return filepath.Join(p.DstTree...)
}

func (p provisioner) Copy() error {
body, err := p.FS.ReadFile(p.EmbedPath())
if err != nil {
return err
}
err = os.WriteFile(p.DstPath(), body, configFilePermission)
if err != nil {
return err
}
// Make sure the permission even for umask problem
err = os.Chmod(p.DstPath(), configFilePermission)
if err != nil {
return err
}

return nil
}

func main() {
pwshProfilePathFlag := flag.String("pwsh_profile_path", "", "Specify PowerShell profile path")
flag.Parse()
// $PROFILE is an "Automatic Variables", not ENV
// https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4
pwshProfilePath := filepath.Clean(*pwshProfilePathFlag)

if pwshProfilePath == "" {
flag.Usage()
log.Fatalf("called with wrong arguments")
}

func provisioners(pwshProfilePath string) []provisioner {
homePath, err := os.UserHomeDir()
if err != nil {
log.Fatalf("Failed to get home directory: %+v", err)
Expand Down Expand Up @@ -101,19 +72,50 @@ func main() {
log.Fatalf("Failed to create path that will have PowerShell profiles: %+v", err)
}

provisioners := []provisioner{
return []provisioner{
newProvisioner([]string{"starship", "starship.toml"}, []string{homePath, ".config", "starship.toml"}),
newProvisioner([]string{"alacritty", "common.toml"}, []string{homePath, ".config", "alacritty", "common.toml"}),
// TODO: Copy all TOMLs under themes
newProvisioner([]string{"alacritty", "themes", "iceberg-dark.toml"}, []string{homePath, ".config", "alacritty", "themes", "iceberg-dark.toml"}),
newProvisioner([]string{"alacritty", "windows.toml"}, []string{appdataPath, "alacritty", "alacritty.toml"}),
newProvisioner([]string{"windows", "powershell", "Profile.ps1"}, []string{pwshProfilePath}),
newProvisioner([]string{"winget", "winget-pkgs-basic.json"}, []string{tmpdirPath, "winget-pkgs-basic.json"}),
newProvisioner([]string{"winget", "winget-pkgs-entertainment.json"}, []string{tmpdirPath, "winget-pkgs-entertainment.json"}),
newProvisioner([]string{"winget", "winget-pkgs-storage.json"}, []string{tmpdirPath, "winget-pkgs-storage.json"}),
newProvisioner([]string{"windows", "winget", "winget-pkgs-basic.json"}, []string{tmpdirPath, "winget-pkgs-basic.json"}),
newProvisioner([]string{"windows", "winget", "winget-pkgs-entertainment.json"}, []string{tmpdirPath, "winget-pkgs-entertainment.json"}),
newProvisioner([]string{"windows", "winget", "winget-pkgs-storage.json"}, []string{tmpdirPath, "winget-pkgs-storage.json"}),
}
}

func (p provisioner) Copy() error {
body, err := p.FS.ReadFile(p.EmbedPath())
if err != nil {
return err
}
err = os.WriteFile(p.DstPath(), body, configFilePermission)
if err != nil {
return err
}
// Make sure the permission even for umask problem
err = os.Chmod(p.DstPath(), configFilePermission)
if err != nil {
return err
}

return nil
}

func main() {
pwshProfilePathFlag := flag.String("pwsh_profile_path", "", "Specify PowerShell profile path")
flag.Parse()
// $PROFILE is an "Automatic Variables", not ENV
// https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4
pwshProfilePath := filepath.Clean(*pwshProfilePathFlag)

if pwshProfilePath == "" {
flag.Usage()
log.Fatalf("called with wrong arguments")
}

for _, p := range provisioners {
for _, p := range provisioners(pwshProfilePath) {
log.Printf("%s => %s,\n", p.EmbedPath(), p.DstPath())
err := p.Copy()
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions cmd/winit-conf/winit-conf_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"testing"

"github.com/kachick/dotfiles/config"
)

func TestAssets(t *testing.T) {
for _, p := range provisioners("dummy_path") {
_, err := config.WindowsAssets.ReadFile(p.EmbedPath())
if err != nil {
t.Fatalf("embed file not found: %v", err)
}
}
}
14 changes: 0 additions & 14 deletions config/windows-assets_test.go

This file was deleted.

0 comments on commit 77fc9cf

Please sign in to comment.