From 66eb33b7246295b53b097ea252695204d8514dfd Mon Sep 17 00:00:00 2001 From: tridentlead Date: Wed, 4 Jan 2017 10:21:35 -0500 Subject: [PATCH 1/2] Added support for pre and post commands Two new fields were added to the config. Precmds runs before cmds and links. Postcmds runs after cmds and links. Cmds is no longer necessary but was left in for compatibility. --- task.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/task.go b/task.go index f99c358..2619905 100644 --- a/task.go +++ b/task.go @@ -28,12 +28,14 @@ import ( ) type task struct { - Deps []string - Links [][]string - Cmds [][]string - Envs [][]string - Accepts [][]string - Rejects [][]string + Deps []string + Links [][]string + Precmds [][]string + Cmds [][]string + Postcmds [][]string + Envs [][]string + Accepts [][]string + Rejects [][]string } func (t *task) deps(conf *config) []string { @@ -61,6 +63,14 @@ func (t *task) process(conf *config) error { } } + if conf.flags&flagNoCmds == 0 { + for _, currCmd := range t.Precmds { + if err := processCmd(currCmd, true, conf); err != nil { + return err + } + } + } + if conf.flags&flagNoCmds == 0 { for _, currCmd := range t.Cmds { if err := processCmd(currCmd, true, conf); err != nil { @@ -77,7 +87,15 @@ func (t *task) process(conf *config) error { } } - return nil + if conf.flags&flagNoCmds == 0 { + for _, currCmd := range t.Postcmds { + if err := processCmd(currCmd, true, conf); err != nil { + return err + } + } + } + + return nil } func (t *task) skippable(conf *config) bool { From fc6740c07c10668404147c14816f1e4c25bb011e Mon Sep 17 00:00:00 2001 From: tridentlead Date: Wed, 4 Jan 2017 23:38:21 -0500 Subject: [PATCH 2/2] Adopt changes required by upstream maintainer This commit switches indentation to tabs, rather than spaces, removes an unnecessary conditional check and adopts the project naming convention. It also updates the documentation to reflect the changes it creates. --- README.md | 11 ++++++----- task.go | 19 ++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b1d865c..c83bf47 100644 --- a/README.md +++ b/README.md @@ -223,11 +223,12 @@ shown below: Homemaker will process the dependency tasks before processing the task itself. -In addition to creating links, Homemaker is capable of executing commands on a per-task basis. Commands should be -defined in an array called `cmds`, split into an item per each command line argument. All of the commands are executed -with `dest` as the working directory (as mentioned previously, this defaults to your home directory). If any command -returns a nonzero exit code, Homemaker will display an error message and prompt the user to determine if it should -*abort*, *retry*, or *cancel*. +In addition to creating links, Homemaker is capable of executing commands on a per-task basis. Homemaker can commands both +before and after linking your configuration. Commands should be placed in either an array, under the field `precmds` or +`postcmds` (for commands to be run before and after linking respectively). These commands should be split into an array of +strings, with each entry corresponding to one command line argument. All of the commands are executed with `dest` as +the working directory (as mentioned previously, this defaults to your home directory). If any command returns a nonzero +exit code, Homemaker will display an error message and prompt the user to determine if it should *abort*, *retry*, or *cancel*. The example task below will clone and install configuration files for Vim into the `~/.config` directory, and create links to it from the home directory. You may notice that this task references an environment variable (set by Homemaker diff --git a/task.go b/task.go index 2619905..f11ffcb 100644 --- a/task.go +++ b/task.go @@ -30,9 +30,9 @@ import ( type task struct { Deps []string Links [][]string - Precmds [][]string + CmdsPre [][]string Cmds [][]string - Postcmds [][]string + CmdsPost [][]string Envs [][]string Accepts [][]string Rejects [][]string @@ -63,15 +63,12 @@ func (t *task) process(conf *config) error { } } - if conf.flags&flagNoCmds == 0 { - for _, currCmd := range t.Precmds { + if conf.flags&flagNoCmds == 0 { + for _, currCmd := range t.CmdsPre { if err := processCmd(currCmd, true, conf); err != nil { return err } } - } - - if conf.flags&flagNoCmds == 0 { for _, currCmd := range t.Cmds { if err := processCmd(currCmd, true, conf); err != nil { return err @@ -87,15 +84,15 @@ func (t *task) process(conf *config) error { } } - if conf.flags&flagNoCmds == 0 { - for _, currCmd := range t.Postcmds { + if conf.flags&flagNoCmds == 0 { + for _, currCmd := range t.CmdsPost { if err := processCmd(currCmd, true, conf); err != nil { return err } } } - - return nil + + return nil } func (t *task) skippable(conf *config) bool {