apply go formatting

pull/41/head
Marcus Kok 1 year ago
parent 8ebfc35ccc
commit f894e8eceb

@ -17,7 +17,7 @@ func init() {
RootCmd.AddCommand(addCommand)
}
var addCommand = &cobra.Command {
var addCommand = &cobra.Command{
Use: "add",
Short: "Adds config to be tracked by dotctl",
Long: "TODO: add longer description", // TODO add more description
@ -36,7 +36,7 @@ func runAddCommand(cmd *cobra.Command, args []string) {
configSrc := args[0]
dirs := strings.Split(configSrc, "/")
name := dirs[len(dirs) - 1] // take the last section of the path, this should be the name
name := dirs[len(dirs)-1] // take the last section of the path, this should be the name
if name[0] == '.' {
name = name[1:]
}
@ -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,14 +36,14 @@ 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)
}
}
}
var initCommand = &cobra.Command {
var initCommand = &cobra.Command{
Use: "init",
Short: "Copy configs to dotfile directory",
Long: "Searches existing config directory for configs and then copies them to dotfile directory",
@ -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())
}
@ -83,7 +82,7 @@ func runInitCommand(cmd *cobra.Command, args []string) {
log.Fatal(err)
}
gitignoreContent := []byte (`
gitignoreContent := []byte(`
# ignore dotctl config for individual installations
dotctl/

@ -15,15 +15,13 @@ func init() {
linkCommand.AddCommand(listCommand)
}
var linkCommand = &cobra.Command {
var linkCommand = &cobra.Command{
Use: "link",
Run: runLinkCommand,
Short: "generate symlinks according to config",
Long: "add longer description", // TODO add longer description here
}
func runLinkCommand(cmd *cobra.Command, args []string) {
fs := FileSystem
fmt.Println("Symlinking dotfiles...")
@ -37,13 +35,12 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
}
dotPath := filepath.Join(dotfileRoot, configName)
if configPath == ""{
if configPath == "" {
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,8 +66,7 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
}
}
var listCommand = &cobra.Command {
var listCommand = &cobra.Command{
Use: "list",
Run: runListCommand,
Short: "list configs that should be symlinked",

@ -13,7 +13,7 @@ func init() {
RootCmd.AddCommand(removeCommand)
}
var removeCommand = &cobra.Command {
var removeCommand = &cobra.Command{
Use: "rm",
Short: "remove dotfile link",
Long: "TODO: add longer description",
@ -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
}

@ -14,14 +14,14 @@ func init() {
RootCmd.AddCommand(statusCommand)
}
var statusCommand = &cobra.Command {
var statusCommand = &cobra.Command{
Use: "status",
Short: "View status of dotctl",
Long: "TODO: add longer description",
Run: runStatusCommand,
}
func runStatusCommand(cmd *cobra.Command, args[]string) {
func runStatusCommand(cmd *cobra.Command, args []string) {
fs := FileSystem
links := viper.GetStringMapString("links")
@ -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,18 +109,17 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
passwordVal, err := password.Run()
CheckIfError(err)
fmt.Println("Pulling from remote")
err = w.Pull(&git.PullOptions{
RemoteName: "origin",
Auth: &http.BasicAuth {
Auth: &http.BasicAuth{
Username: usernameVal,
Password: passwordVal,
},
})
if err != nil{
if err != nil {
fmt.Println(err)
} else {
fmt.Fprintf(cmd.OutOrStdout(), "successfully pulled from %s", origin)
@ -133,7 +132,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
if !status.IsClean() {
fmt.Println("Changes detected, do you want to push them?")
confirm := promptui.Prompt {
confirm := promptui.Prompt{
Label: "commit and push changes",
IsConfirm: true,
}
@ -169,14 +168,14 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
obj, err := r.CommitObject(commit)
if err != nil {
log.Fatalf("Cannot commit: %s",err)
log.Fatalf("Cannot commit: %s", err)
}
fmt.Println(obj)
err = r.Push(&git.PushOptions{
RemoteName: "origin",
Auth: &http.BasicAuth {
Auth: &http.BasicAuth{
Username: usernameVal,
Password: passwordVal,
},

@ -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()
@ -21,7 +20,7 @@ func TestLinkCommand(t *testing.T) {
homedir := os.Getenv("HOME")
fs.MkdirAll(filepath.Join(homedir, "dotfiles/dotctl"), 0755)
links := map[string]string {
links := map[string]string{
"someconfig": filepath.Join(homedir, ".config/someconfig"),
}
viper.Set("links", links)
@ -42,4 +41,3 @@ func TestLinkCommand(t *testing.T) {
assert.Equal(t, expected, actual.String(), "actual differs from expected")
}

@ -22,7 +22,7 @@ func TestStatusCommand(t *testing.T) {
fs.MkdirAll(filepath.Join(homedir, "dotfiles/someconfig"), 0755)
fs.MkdirAll(filepath.Join(homedir, "dotfiles/somelinkedconfig"), 0755)
var links = map[string]string {
var links = map[string]string{
"somelinkedconfig": "configpath",
}

@ -9,7 +9,7 @@ import (
"github.com/spf13/afero"
)
func CopyFile(os afero.Fs, srcFile, destFile string) error{
func CopyFile(os afero.Fs, srcFile, destFile string) error {
// helper function to copy files over
// ignore pre-existing git files
if strings.Contains(srcFile, ".git") {
@ -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