renaming to dotctl (#16)

pull/18/head
Marcus Kok 2 years ago committed by GitHub
parent 2356fab9d4
commit 16051e8645
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

1
.gitignore vendored

@ -3,6 +3,7 @@
#
# Binaries for programs and plugins
bender
dotctl
*.exe
*.exe~
*.dll

@ -1,5 +1,5 @@
clean:
rm -rf test/bender_test 2> /dev/null
rm -rf test/dotctl_test 2> /dev/null
rm -rf tmp 2> /dev/null
sandbox:

@ -1,9 +1,8 @@
# Bender
![](assets/bender.png)
# Dotctl
A cli tool to manage your dotfiles
## About
Bender is a tool to help you easily manage your dotfiles and sync them across separate machines using
Dotctl is a tool to help you easily manage your dotfiles and sync them across separate machines using
git. It aims to abstract away the manual effort of symlinking your dotfiles to config directories and
updating them with git.
@ -14,11 +13,11 @@ updating them with git.
```bash
# init sets up the config file and directory to hold all dotfiles
bender init --dotfile-path=/path/to/dotfile/repo
# add a config directory for bender to track
bender add /.config/nvim
dotctl init --dotfile-path=/path/to/dotfile/repo
# add a config directory for dotctl to track
dotctl add /.config/nvim
# create symlinks
bender link
dotctl link
```
## Development

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"
"github.com/Marcusk19/bender/tools"
"github.com/Marcusk19/dotctl/tools"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -17,7 +17,7 @@ func init() {
var addCommand = &cobra.Command {
Use: "add",
Short: "Adds config to be tracked by bender",
Short: "Adds config to be tracked by dotctl",
Long: "TODO: add longer description", // TODO add more description
Run: runAddCommand,
}
@ -36,7 +36,7 @@ func runAddCommand(cmd *cobra.Command, args []string) {
viper.Set(name, configSrc)
err := viper.WriteConfig()
if err != nil {
fmt.Printf("Problem updating bender config %s", err)
fmt.Printf("Problem updating dotctl config %s", err)
}
dotfilePath := viper.Get("dotfile-path").(string)

@ -1,59 +0,0 @@
package cmd
import (
"fmt"
"log"
"time"
"github.com/Marcusk19/bender/tools"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(backupCommand)
}
var backupCommand = &cobra.Command {
Use: "backup",
Short: "Add and commit files in dotfiles directory",
Run: runBackup,
}
func runBackup(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "Backing up %s...\n", DotfilePath)
r, err := git.PlainOpen(DotfilePath)
if err != nil {
log.Fatal(err)
}
worktree, err := r.Worktree()
if err != nil {
log.Fatal(err)
}
gitAddFiles(worktree, tools.AppFs)
commitMessage := "backup " + time.Now().String()
commit, err := worktree.Commit(commitMessage, &git.CommitOptions{
Author: &object.Signature{
Name: "bender CLI",
Email: "example@example.com",
When: time.Now(),
},
})
if err != nil {
log.Fatal(err.Error())
}
obj, err := r.CommitObject(commit)
if err != nil {
log.Fatal(err)
}
fmt.Println(obj)
}

@ -7,7 +7,7 @@ import (
"path"
"path/filepath"
"github.com/Marcusk19/bender/tools"
"github.com/Marcusk19/dotctl/tools"
"github.com/go-git/go-git/v5"
"github.com/spf13/afero"
"github.com/spf13/cobra"
@ -55,18 +55,18 @@ func runInitCommand(cmd *cobra.Command, args []string) {
fs := FileSystem
// if user has passed a dotfile path flag need to add it to
// viper's search path for a config file
viper.AddConfigPath(filepath.Join(DotfilePath, "bender"))
viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl"))
if(viper.Get("testing") == true && fs.Name() != "MemMapFS") {
log.Fatalf("wrong filesystem, got %s", fs.Name())
}
err := fs.MkdirAll(path.Join(DotfilePath, "bender"), 0755)
err := fs.MkdirAll(path.Join(DotfilePath, "dotctl"), 0755)
if err != nil {
log.Fatalf("Unable to create dotfile structure: %s", error.Error(err))
}
_, err = fs.Create(path.Join(DotfilePath, "bender/config"))
_, err = fs.Create(path.Join(DotfilePath, "dotctl/config"))
if err != nil {
panic(fmt.Errorf("Unable to create config file %w", err))
}

@ -13,6 +13,8 @@ import (
var linkCommand = &cobra.Command {
Use: "link",
Run: runLinkCommand,
Short: "generate symlinks according to config",
Long: "add longer description", // TODO add longer description here
}
func init() {
@ -29,7 +31,7 @@ func runLinkCommand(cmd *cobra.Command, args []string) {
}
for _, entry := range(entries) {
configName := entry.Name()
if configName == ".git" || configName == "bender" {
if configName == ".git" || configName == "dotctl" {
continue
}
dotPath := filepath.Join(dotfileRoot, entry.Name())

@ -15,9 +15,9 @@ import (
var RootCmd = &cobra.Command{
Use: "bender",
Use: "dotctl",
Short: "dotfile management",
Long: `Bender is a CLI tool for syncing your
Long: `Dotctl is a CLI tool for syncing your
dotfiles. It provides an opiniated way to symlink
a dotfile directory to various config directories.`,
}
@ -66,13 +66,13 @@ func init() {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("./tmp/dotfiles/bender")
viper.AddConfigPath(filepath.Join(DotfilePath, "bender"))
viper.AddConfigPath("./tmp/dotfiles/dotctl")
viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl"))
err := viper.ReadInConfig()
if err != nil {
fmt.Println("No config detected. You can generate one by using 'bender init'")
fmt.Println("No config detected. You can generate one by using 'dotctl init'")
}
FileSystem = UseFilesystem()

@ -28,7 +28,7 @@ func init() {
"URL of remote repository",
)
viper.BindPFlag("bender-origin", syncCommand.Flags().Lookup("remote"))
viper.BindPFlag("dotctl-origin", syncCommand.Flags().Lookup("remote"))
}
var syncCommand = &cobra.Command{
@ -62,7 +62,7 @@ func gitAddFiles(worktree *git.Worktree, fs afero.Fs) error {
}
func runSyncCommand(cmd *cobra.Command, args []string) {
origin := viper.GetString("bender-origin")
origin := viper.GetString("dotctl-origin")
if origin == "" {
fmt.Fprintln(cmd.OutOrStdout(), "No remote repository found")
return
@ -126,7 +126,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
commit, err := w.Commit(commitMessage, &git.CommitOptions{
Author: &object.Signature{
Name: "bender CLI",
Name: "dotctl CLI",
Email: "example@example.com",
When: time.Now(),
},

@ -1,4 +1,4 @@
module github.com/Marcusk19/bender
module github.com/Marcusk19/dotctl
go 1.21.0

@ -4,7 +4,7 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package main
import "github.com/Marcusk19/bender/cmd"
import "github.com/Marcusk19/dotctl/cmd"
func main() {
cmd.Execute()

@ -4,7 +4,7 @@ import (
"os"
"testing"
"github.com/Marcusk19/bender/tools"
"github.com/Marcusk19/dotctl/tools"
"github.com/spf13/afero"
)

@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"
"github.com/Marcusk19/bender/cmd"
"github.com/Marcusk19/dotctl/cmd"
"github.com/spf13/afero"
"github.com/spf13/viper"
)
@ -15,18 +15,18 @@ func TestInitCommand(t *testing.T) {
fs := cmd.FileSystem
bender := cmd.RootCmd
dotctl := cmd.RootCmd
actual := new(bytes.Buffer)
bender.SetOut(actual)
bender.SetErr(actual)
bender.SetArgs([]string{"init", "--dotfile-path=bender_test/dotfiles"})
dotctl.SetOut(actual)
dotctl.SetErr(actual)
dotctl.SetArgs([]string{"init", "--dotfile-path=dotctl_test/dotfiles"})
bender.Execute()
dotctl.Execute()
homedir := "bender_test/"
homedir := "dotctl_test/"
_, err := afero.ReadFile(fs, filepath.Join(homedir, "dotfiles/bender/config"))
_, err := afero.ReadFile(fs, filepath.Join(homedir, "dotfiles/dotctl/config"))
if err != nil {
t.Error(err.Error())
}

@ -7,7 +7,7 @@ import (
"path/filepath"
"testing"
"github.com/Marcusk19/bender/cmd"
"github.com/Marcusk19/dotctl/cmd"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
@ -15,14 +15,14 @@ import (
func TestLinkCommand(t *testing.T) {
setUpTesting()
bender := cmd.RootCmd
dotctl := cmd.RootCmd
actual := new(bytes.Buffer)
bender.SetOut(actual)
bender.SetErr(actual)
bender.SetArgs([]string{"link"})
dotctl.SetOut(actual)
dotctl.SetErr(actual)
dotctl.SetArgs([]string{"link"})
bender.Execute()
dotctl.Execute()
homedir := os.Getenv("HOME")
someconfig := filepath.Join(homedir, ".config/someconfig/")
@ -38,8 +38,8 @@ func TestLinkCommand(t *testing.T) {
func setUpTesting() {
fs := cmd.FileSystem
homedir := os.Getenv("HOME")
fs.MkdirAll(filepath.Join(homedir, ".dotfiles/bender"), 0755)
fs.Create(filepath.Join(homedir, ".dotfiles/bender/config"))
fs.MkdirAll(filepath.Join(homedir, ".dotfiles/dotctl"), 0755)
fs.Create(filepath.Join(homedir, ".dotfiles/dotctl/config"))
fs.MkdirAll(filepath.Join(homedir, ".dotfiles/someconfig/"), 0755)
viper.Set("dotfile-path", filepath.Join(homedir, ".dotfiles"))
@ -50,5 +50,5 @@ func setUpTesting() {
func tearDownTesting() {
fs := cmd.FileSystem
fs.RemoveAll("bender_test/")
fs.RemoveAll("dotctl_test/")
}

@ -4,17 +4,17 @@ import (
"bytes"
"testing"
"github.com/Marcusk19/bender/cmd"
"github.com/Marcusk19/dotctl/cmd"
"github.com/stretchr/testify/assert"
)
func TestPrettyCommand(t *testing.T) {
bender := cmd.RootCmd
dotctl := cmd.RootCmd
actual := new(bytes.Buffer)
bender.SetOut(actual)
bender.SetErr(actual)
bender.SetArgs([]string{"pretty", "fixtures/test_pretty.txt"})
bender.Execute()
dotctl.SetOut(actual)
dotctl.SetErr(actual)
dotctl.SetArgs([]string{"pretty", "fixtures/test_pretty.txt"})
dotctl.Execute()
expected := "The end of this sentence should start a newline. \nThe next sentence should be indented below this one.\n\tHello this is the end of the text"
assert.Equal(t, expected, actual.String(), "actual value differs from expected")

Loading…
Cancel
Save