working copy

pull/3/head
Marcus Kok 2 years ago
parent a992bcde84
commit c0ad0468b7

@ -25,7 +25,10 @@ func copyExistingConfigs(programs []string, destRootOpt ...string) {
for _, program := range(programs) { for _, program := range(programs) {
// TODO: do something here // TODO: do something here
print(configRoot + program) print(configRoot + program)
tools.CopyDir(filepath.Join(configRoot, program), filepath.Join(destRoot, program)) err := tools.CopyDir(filepath.Join(configRoot, program), filepath.Join(destRoot, program))
if err != nil {
log.Fatal(err)
}
} }
} }
@ -55,11 +58,11 @@ var initCommand = &cobra.Command {
log.Fatal("path needs trailing slash") log.Fatal("path needs trailing slash")
} }
var files []string var programs []string
var acceptedfiles [3] string var acceptedprograms [3] string
acceptedfiles[0] = "nvim" acceptedprograms[0] = "nvim"
acceptedfiles[1] = "tmux" acceptedprograms[1] = "tmux"
acceptedfiles[2] = "alacritty" acceptedprograms[2] = "alacritty"
err := filepath.Walk(rootpath, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(rootpath, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
@ -67,9 +70,9 @@ var initCommand = &cobra.Command {
return nil return nil
} }
for _, acceptedfile := range(acceptedfiles) { for _, acceptedprogram := range(acceptedprograms) {
if path == rootpath + acceptedfile { if path == rootpath + acceptedprogram {
files = append(files, path[len(rootpath):]) programs = append(programs, path[len(rootpath):])
} }
} }
return nil return nil
@ -80,11 +83,12 @@ var initCommand = &cobra.Command {
} }
fmt.Fprintf(cmd.OutOrStdout(), "binaries installed: \n =======================\n") fmt.Fprintf(cmd.OutOrStdout(), "binaries installed: \n =======================\n")
for _, file := range(files) { for _, program := range(programs) {
fmt.Fprintf(cmd.OutOrStdout(), file + "\n" ) fmt.Fprintf(cmd.OutOrStdout(), program + "\n" )
} }
createDotfileStructure(files) createDotfileStructure(programs)
copyExistingConfigs(programs)
}, },
} }

@ -4,11 +4,13 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"log"
"path/filepath" "path/filepath"
) )
func CopyFile(srcFile, destFile string) error{ func CopyFile(srcFile, destFile string) error{
// helper function to copy files over // helper function to copy files over
log.Printf("copy of %s to %s\n", srcFile, destFile)
sourceFileStat, err := os.Stat(srcFile) sourceFileStat, err := os.Stat(srcFile)
if err != nil { if err != nil {
return err return err
@ -29,18 +31,29 @@ func CopyFile(srcFile, destFile string) error{
return err return err
} }
defer destination.Close() defer destination.Close()
_, err = io.Copy(destination, source) _, err = io.Copy(destination, source)
return err return err
} }
func CopyDir(srcDir, destDir string) error { func CopyDir(srcDir, destDir string) error {
log.Printf("copying from %s to %s\n", srcDir, destDir)
entries, err := os.ReadDir(srcDir) entries, err := os.ReadDir(srcDir)
if err != nil { if err != nil {
return err return err
} }
log.Printf("entries found: %s\n", entries)
for _, entry := range(entries) { for _, entry := range(entries) {
if entry.Type().IsDir() {
err := os.MkdirAll(filepath.Join(destDir, entry.Name()), os.ModePerm)
if err != nil {
return err
}
CopyDir(filepath.Join(srcDir, entry.Name()), filepath.Join(destDir, entry.Name()))
continue
}
sourcePath := filepath.Join(srcDir, entry.Name()) sourcePath := filepath.Join(srcDir, entry.Name())
destPath := filepath.Join(destDir, entry.Name()) destPath := filepath.Join(destDir, entry.Name())

Loading…
Cancel
Save