forked from hypnoglow/dotbro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb72ef
commit ba71fe9
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
type Configuration struct { | ||
Directories Directories | ||
Mapping map[string]string | ||
Init map[string][]string | ||
Files Files | ||
Filepath string | ||
} | ||
|
@@ -42,19 +43,20 @@ func NewConfiguration(filename string) (conf *Configuration, err error) { | |
case ".json": | ||
conf, err = fromJSON(filename) | ||
default: | ||
err = fmt.Errorf("Cannot read config file %s : unknown extension. Supported: conf, toml.", filename) | ||
err = fmt.Errorf("Cannot read config file %s : unknown extension. Supported: json, toml.", filename) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
conf.Filepath = filename | ||
This comment has been minimized.
Sorry, something went wrong.
flowchartsman
Author
Owner
|
||
|
||
conf, err = processConf(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
conf.Filepath = filename | ||
return conf, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,19 @@ func ParseArguments(argv []string) (map[string]interface{}, error) { | |
usage := `dotbro - simple yet effective dotfiles manager. | ||
Usage: | ||
dotbro [options] [--config=<filepath>] | ||
dotbro [options] | ||
dotbro init [options] | ||
dotbro add [options] <filename> | ||
dotbro -h | --help | ||
dotbro --version | ||
Common options: | ||
-c --config=<filepath> Dotbro's configuration file in JSON or TOML format. | ||
[default: dotbro.toml] | ||
This comment has been minimized.
Sorry, something went wrong.
flowchartsman
Author
Owner
|
||
-q --quiet Quiet mode. Do not print any output, except warnings | ||
and errors. | ||
-d --dry Dry mode. Do not take any action, instead print what | ||
WOULD happen (suppresses --quiet). | ||
-v --verbose Verbose mode. Detailed output. | ||
Add options: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
. "github.com/logrusorgru/aurora" | ||
) | ||
|
||
func runInitCommands(config *Configuration, outputer Outputer) error { | ||
if err := prepInit(outputer); err != nil { | ||
return err | ||
} | ||
for _, section := range []string{"common", currentOS, "after"} { | ||
commands, has := config.Init[section] | ||
if !has { | ||
return nil | ||
} | ||
outputer.OutInfo("--> Running [%s] init commands...", section) | ||
|
||
for _, command := range commands { | ||
// replace any occurrence of %DOTFILEDIR with dotfile directory | ||
command = strings.Replace(command, "%DOTFILEDIR", config.Directories.Dotfiles, -1) | ||
if dry { | ||
outputer.OutInfo(" %s would run: '%s'", Blue("❯"), command) | ||
continue | ||
} | ||
if err := runCommand(command, outputer); err != nil { | ||
//maybe? | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
var runCmd string | ||
|
||
func prepInit(outputer Outputer) error { | ||
var err error | ||
runCmd, err = exec.LookPath("bash") | ||
if err != nil { | ||
runCmd, err = exec.LookPath("sh") | ||
if err != nil { | ||
return fmt.Errorf("unable to find 'bash' or 'sh', cannot run init commands: %s", err) | ||
} | ||
outputer.OutWarn("'bash' missing, using 'sh'") | ||
} | ||
return nil | ||
} | ||
|
||
func runCommand(command string, outputer Outputer) error { | ||
cmd := exec.Command(runCmd, "-c", command) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stdout | ||
if err := cmd.Run(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
unrelated bug fixed here: doesn't actually support
.conf