Skip to content

Commit

Permalink
Merge pull request #33 from tj/add-user
Browse files Browse the repository at this point in the history
add user
  • Loading branch information
yields committed Aug 31, 2019
2 parents d1ed756 + 8853dad commit 2b0df1d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/robo.yml
dist
14 changes: 14 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ variables:
stage: bastion-stage
```

Along with your own custom variables, robo defines the following variables:

```bash
$ robo variables

robo.file: /Users/amir/dev/src/github.com/tj/robo/robo.yml
robo.path: /Users/amir/dev/src/github.com/tj/robo

user.home: /Users/amir
user.name: Amir Abushareb
user.username: amir

```

### Environment

Tasks may define `env` key with an array of environment variables, this allows you
Expand Down
4 changes: 4 additions & 0 deletions _examples/user/user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

user:
summary: print the current user variables
command: echo user={{ .user }}
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bytes"
"io/ioutil"
"os/user"
"path"
"text/template"

Expand Down Expand Up @@ -76,6 +77,17 @@ func New(file string) (*Config, error) {
}
}

// Add the current user.
if _, ok := c.Variables["user"]; !ok {
if user, err := user.Current(); err == nil {
c.Variables["user"] = map[string]string{
"name": user.Name,
"username": user.Username,
"home": user.HomeDir,
}
}
}

// Interpolate variables.
if err := c.Eval(); err != nil {
return nil, err
Expand Down

0 comments on commit 2b0df1d

Please sign in to comment.