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)
}

@ -14,7 +14,6 @@ import (
"github.com/spf13/viper"
)
func init() {
RootCmd.AddCommand(initCommand)
}
@ -24,7 +23,7 @@ func copyExistingConfigs(programs []string, fs afero.Fs) {
destRoot := DotfilePath
configRoot := ConfigPath
for _, program := range(programs) {
for _, program := range programs {
// TODO: do something here
err := tools.CopyDir(fs, filepath.Join(configRoot, program), filepath.Join(destRoot, program))
if err != nil {
@ -37,7 +36,7 @@ func createDotfileStructure(programs []string, fs afero.Fs) {
// takes list of programs and creates dotfiles for them
dotfileRoot := DotfilePath
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 {
log.Fatal(err)
}
@ -58,7 +57,7 @@ func runInitCommand(cmd *cobra.Command, args []string) {
testing := viper.GetBool("testing")
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())
}

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

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

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

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

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

@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
)
func TestLinkCommand(t *testing.T) {
viper.Set("testing", true)
cmd.FileSystem = afero.NewMemMapFs()
@ -42,4 +41,3 @@ func TestLinkCommand(t *testing.T) {
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)
}
source, err := os.Open(srcFile)
if err != nil {
return err
@ -51,7 +50,7 @@ func CopyDir(os afero.Fs, srcDir, destDir string) error {
return err
}
for _, entry := range(entries) {
for _, entry := range entries {
if entry.IsDir() {
if entry.Name() == ".git" {
continue

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

Loading…
Cancel
Save