apply go formatting (#41)

pull/42/head
Marcus Kok 1 year ago committed by GitHub
parent 8ebfc35ccc
commit a135494bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -104,4 +104,3 @@ func addConfigToDir(fs afero.Fs, configSrc, dotfileDest string) {
fmt.Printf("Copied %s -> %s\n", configSrc, dotfileDest) fmt.Printf("Copied %s -> %s\n", configSrc, dotfileDest)
} }

@ -14,7 +14,6 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func init() { func init() {
RootCmd.AddCommand(initCommand) RootCmd.AddCommand(initCommand)
} }
@ -24,7 +23,7 @@ func copyExistingConfigs(programs []string, fs afero.Fs) {
destRoot := DotfilePath destRoot := DotfilePath
configRoot := ConfigPath configRoot := ConfigPath
for _, program := range(programs) { for _, program := range programs {
// TODO: do something here // TODO: do something here
err := tools.CopyDir(fs, filepath.Join(configRoot, program), filepath.Join(destRoot, program)) err := tools.CopyDir(fs, filepath.Join(configRoot, program), filepath.Join(destRoot, program))
if err != nil { if err != nil {
@ -37,7 +36,7 @@ func createDotfileStructure(programs []string, fs afero.Fs) {
// takes list of programs and creates dotfiles for them // takes list of programs and creates dotfiles for them
dotfileRoot := DotfilePath dotfileRoot := DotfilePath
fmt.Printf("creating dotfile directory structure at %s\n", dotfileRoot) fmt.Printf("creating dotfile directory structure at %s\n", dotfileRoot)
for _, program := range(programs) { for _, program := range programs {
if err := fs.MkdirAll(path.Join(dotfileRoot, program), os.ModePerm); err != nil { if err := fs.MkdirAll(path.Join(dotfileRoot, program), os.ModePerm); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -58,7 +57,7 @@ func runInitCommand(cmd *cobra.Command, args []string) {
testing := viper.GetBool("testing") testing := viper.GetBool("testing")
viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl")) viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl"))
if(viper.Get("testing") == true && fs.Name() != "MemMapFS") { if viper.Get("testing") == true && fs.Name() != "MemMapFS" {
log.Fatalf("wrong filesystem, got %s", fs.Name()) log.Fatalf("wrong filesystem, got %s", fs.Name())
} }

@ -15,7 +15,6 @@ func init() {
linkCommand.AddCommand(listCommand) linkCommand.AddCommand(listCommand)
} }
var linkCommand = &cobra.Command{ var linkCommand = &cobra.Command{
Use: "link", Use: "link",
Run: runLinkCommand, Run: runLinkCommand,
@ -23,7 +22,6 @@ var linkCommand = &cobra.Command {
Long: "add longer description", // TODO add longer description here Long: "add longer description", // TODO add longer description here
} }
func runLinkCommand(cmd *cobra.Command, args []string) { func runLinkCommand(cmd *cobra.Command, args []string) {
fs := FileSystem fs := FileSystem
fmt.Println("Symlinking dotfiles...") fmt.Println("Symlinking dotfiles...")
@ -41,9 +39,8 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "Warning: could not find config for %s\n", configName) fmt.Fprintf(cmd.OutOrStdout(), "Warning: could not find config for %s\n", configName)
} }
// destination needs to be removed before symlink // destination needs to be removed before symlink
if(DryRun) { if DryRun {
log.Printf("Existing directory %s will be removed\n", configPath) log.Printf("Existing directory %s will be removed\n", configPath)
} else { } else {
@ -52,10 +49,10 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
testing := viper.Get("testing") testing := viper.Get("testing")
if(DryRun) { if DryRun {
log.Printf("Will link %s -> %s\n", configPath, dotPath) log.Printf("Will link %s -> %s\n", configPath, dotPath)
} else { } else {
if(testing == true) { if testing == true {
fmt.Fprintf(cmd.OutOrStdout(), "%s,%s", configPath, dotPath) fmt.Fprintf(cmd.OutOrStdout(), "%s,%s", configPath, dotPath)
} else { } else {
err := afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath) err := afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
@ -69,7 +66,6 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
} }
} }
var listCommand = &cobra.Command{ var listCommand = &cobra.Command{
Use: "list", Use: "list",
Run: runListCommand, Run: runListCommand,

@ -71,4 +71,3 @@ func runRemoveCommand(cmd *cobra.Command, args []string) {
fmt.Printf("%s symlink removed, copied files over to %s\n", dotfile, dotfileConfigPath) fmt.Printf("%s symlink removed, copied files over to %s\n", dotfile, dotfileConfigPath)
} }

@ -13,7 +13,6 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
var RootCmd = &cobra.Command{ var RootCmd = &cobra.Command{
Use: "dotctl", Use: "dotctl",
Short: "dotfile management", Short: "dotfile management",
@ -40,7 +39,6 @@ var FileSystem afero.Fs
func init() { func init() {
// define flags and config sections // define flags and config sections
// Cobra also supports local flags, which will only run // Cobra also supports local flags, which will only run
// when this action is called directly. // when this action is called directly.
defaultDotPath := os.Getenv("HOME") + "/dotfiles/" defaultDotPath := os.Getenv("HOME") + "/dotfiles/"
@ -83,7 +81,7 @@ func init() {
func UseFilesystem() afero.Fs { func UseFilesystem() afero.Fs {
testing := viper.Get("testing") testing := viper.Get("testing")
if(testing == "true") { if testing == "true" {
return afero.NewMemMapFs() return afero.NewMemMapFs()
} else { } else {
return afero.NewOsFs() return afero.NewOsFs()
@ -96,5 +94,3 @@ func CheckIfError(err error) {
} }
return return
} }

@ -35,15 +35,14 @@ func runStatusCommand(cmd *cobra.Command, args[]string) {
var linkedConfigs []string var linkedConfigs []string
var orphanedConfigs []string var orphanedConfigs []string
fmt.Fprintln(cmd.OutOrStdout(), "Config directories currently in dotfile path:\n") fmt.Fprintln(cmd.OutOrStdout(), "Config directories currently in dotfile path:")
for _, dotfileDir := range(dotfiles) {
for _, dotfileDir := range dotfiles {
dirName := dotfileDir.Name() dirName := dotfileDir.Name()
if !slices.Contains(ignoredDirs, dirName) { if !slices.Contains(ignoredDirs, dirName) {
if links[dirName] != "" { if links[dirName] != "" {
// fmt.Fprintf(cmd.OutOrStdout(), "%s -> %s\n", dirName, links[dirName])
linkedConfigs = append(linkedConfigs, dirName, links[dirName]) linkedConfigs = append(linkedConfigs, dirName, links[dirName])
} else { } else {
// fmt.Fprintln(cmd.OutOrStdout(), dirName)
orphanedConfigs = append(orphanedConfigs, dirName) orphanedConfigs = append(orphanedConfigs, dirName)
} }
} }
@ -56,12 +55,8 @@ func runStatusCommand(cmd *cobra.Command, args[]string) {
fmt.Fprintln(cmd.OutOrStdout(), "Orphaned configs") fmt.Fprintln(cmd.OutOrStdout(), "Orphaned configs")
for _, conf := range(orphanedConfigs) { for _, conf := range orphanedConfigs {
fmt.Fprintln(cmd.OutOrStdout(), conf) fmt.Fprintln(cmd.OutOrStdout(), conf)
} }
} }

@ -53,8 +53,8 @@ func gitAddFiles(worktree *git.Worktree, fs afero.Fs) error {
if err != nil { if err != nil {
return err return err
} }
for _, entry := range(entries) { for _, entry := range entries {
if(entry.Name() == "dotctl") { if entry.Name() == "dotctl" {
continue continue
} }
_, err = worktree.Add(entry.Name()) _, err = worktree.Add(entry.Name())
@ -109,7 +109,6 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
passwordVal, err := password.Run() passwordVal, err := password.Run()
CheckIfError(err) CheckIfError(err)
fmt.Println("Pulling from remote") fmt.Println("Pulling from remote")
err = w.Pull(&git.PullOptions{ err = w.Pull(&git.PullOptions{

@ -12,7 +12,6 @@ func init() {
tools.SetTestFs() tools.SetTestFs()
} }
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
@ -83,4 +82,3 @@ func TestCopyDir(t *testing.T) {
} }
} }

@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestLinkCommand(t *testing.T) { func TestLinkCommand(t *testing.T) {
viper.Set("testing", true) viper.Set("testing", true)
cmd.FileSystem = afero.NewMemMapFs() cmd.FileSystem = afero.NewMemMapFs()
@ -42,4 +41,3 @@ func TestLinkCommand(t *testing.T) {
assert.Equal(t, expected, actual.String(), "actual differs from expected") assert.Equal(t, expected, actual.String(), "actual differs from expected")
} }

@ -25,7 +25,6 @@ func CopyFile(os afero.Fs, srcFile, destFile string) error{
return fmt.Errorf("%s is not a regular file", srcFile) return fmt.Errorf("%s is not a regular file", srcFile)
} }
source, err := os.Open(srcFile) source, err := os.Open(srcFile)
if err != nil { if err != nil {
return err return err
@ -51,7 +50,7 @@ func CopyDir(os afero.Fs, srcDir, destDir string) error {
return err return err
} }
for _, entry := range(entries) { for _, entry := range entries {
if entry.IsDir() { if entry.IsDir() {
if entry.Name() == ".git" { if entry.Name() == ".git" {
continue continue

@ -8,7 +8,6 @@ import (
var AppFs afero.Fs = afero.NewOsFs() var AppFs afero.Fs = afero.NewOsFs()
func SetTestFs() { func SetTestFs() {
log.Println("setting test fs") log.Println("setting test fs")
testFs := afero.NewMemMapFs() testFs := afero.NewMemMapFs()

Loading…
Cancel
Save