aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--main.go29
2 files changed, 18 insertions, 20 deletions
diff --git a/README.md b/README.md
index c21d738..dbbc13a 100644
--- a/README.md
+++ b/README.md
@@ -13,12 +13,11 @@ go get git.sr.ht/~benburwell/conf
## Usage
-To start using conf, you'll need to specify source and destination directories.
-This is currently done through environment variables. For example, to target
-dotfiles in your home directory from a repository at ~/projects/dotfiles, use:
+To start using conf, you'll need to specify a source directory. This is
+currently done through an environment variable. For example, to use a repository
+at ~/projects/dotfiles, use:
* `CONF_SOURCE=~/projects/dotfiles`
-* `CONF_DEST=~`
Now, you can start adopting dotfiles for conf to manage. Let's start with
`.vimrc`:
@@ -28,7 +27,7 @@ $ conf adopt .vimrc
```
You can run this command from anywhere on your system, and conf will place a
-copy of your `$CONF_DEST/.vimrc` file into `$CONF_SOURCE/templates/.vimrc`.
+copy of your `~/.vimrc` file into `$CONF_SOURCE/templates/.vimrc`.
Open up `$CONF_SOURCE/templates/.vimrc`, make a change, and then run `conf apply
.vimrc`. You'll see that conf has updated your vimrc file with your latest
diff --git a/main.go b/main.go
index 2c4c2c4..8c49ce3 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"fmt"
"os"
)
@@ -11,16 +12,9 @@ type Conf struct {
}
func main() {
- conf := &Conf{
- Source: os.Getenv("CONF_SOURCE"),
- Dest: os.Getenv("CONF_DEST"),
- }
- if err := checkdir(conf.Source); err != nil {
- fmt.Printf("could not find $CONF_SOURCE: %v\n", err)
- os.Exit(1)
- }
- if err := checkdir(conf.Dest); err != nil {
- fmt.Printf("could not find $CONF_DEST: %v\n", err)
+ conf, err := loadConf()
+ if err != nil {
+ fmt.Printf("could not load configuration: %v\n", err)
os.Exit(1)
}
if len(os.Args) < 2 {
@@ -44,13 +38,18 @@ func main() {
}
}
-func checkdir(path string) error {
- info, err := os.Stat(path)
+func loadConf() (*Conf, error) {
+ source := os.Getenv("CONF_SOURCE")
+ info, err := os.Stat(source)
if err != nil {
- return err
+ return nil, err
}
if !info.IsDir() {
- return fmt.Errorf("%s is not a directory", path)
+ return nil, errors.New("CONF_SOURCE is not a directory")
+ }
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, err
}
- return nil
+ return &Conf{Source: source, Dest: home}, nil
}