add file walk through path

pull/2/head
Marcusk19 2 years ago
parent 9643d3caa4
commit 8dbe90ce31

@ -3,6 +3,8 @@ package cmd
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
@ -17,7 +19,40 @@ var initCommand = &cobra.Command {
if(len(args) <= 0) {
log.Fatal(cmd.OutOrStdout(), "no arguments provided to init")
}
// we will do something here, for now just print args[0]
fmt.Fprintf(cmd.OutOrStdout(), args[0])
if args[0][len(args[0])-1:] != "/" {
log.Fatal("path needs trailing slash")
}
var files []string
var acceptedfiles [3] string
acceptedfiles[0] = "nvim"
acceptedfiles[1] = "tmux"
acceptedfiles[2] = "alacritty"
rootpath := args[0]
err := filepath.Walk(rootpath, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Fatalf("problem walking path %s", err)
return nil
}
for _, acceptedfile := range(acceptedfiles) {
if path == args[0] + acceptedfile {
files = append(files, path)
}
}
return nil
})
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(cmd.OutOrStdout(), "binaries installed: \n =======================\n")
for _, file := range(files) {
fmt.Fprintf(cmd.OutOrStdout(), file[len(args[0]):] + "\n" )
}
},
}

Loading…
Cancel
Save