Skip to content

Commit

Permalink
A lot of enhancements/house cleaning
Browse files Browse the repository at this point in the history
 - Added () to task definitions
 - Moving task module to alfred(rest coming soon)
 - Formatting
 - Beautifying the readme
  • Loading branch information
kcmerrill committed Mar 4, 2017
1 parent 26c9310 commit 9a53ac5
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 94 deletions.
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# alfred

Because even Batman needs a little help.

[![Build Status](https://travis-ci.org/kcmerrill/alfred.svg?branch=master)](https://travis-ci.org/kcmerrill/alfred) [![Join the chat at https://gitter.im/kcmerrill/alfred](https://badges.gitter.im/kcmerrill/alfred.svg)](https://gitter.im/kcmerrill/alfred?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

![Alfred](https://raw.githubusercontent.com/kcmerrill/alfred/master/assets/alfred.jpg "Alfred")

## What is it

A simple go/yaml powered make file/task runner with a bit of a twist.

## Binaries || Installation

[![MacOSX](https://raw.githubusercontent.com/kcmerrill/go-dist/master/assets/apple_logo.png "Mac OSX")] (http://go-dist.kcmerrill.com/kcmerrill/alfred/mac/amd64) [![Linux](https://raw.githubusercontent.com/kcmerrill/go-dist/master/assets/linux_logo.png "Linux")] (http://go-dist.kcmerrill.com/kcmerrill/alfred/linux/amd64)

via go:
Expand All @@ -20,19 +23,22 @@ via docker:
`$ docker run -v $PWD:$PWD -w $PWD kcmerrill/alfred`

## Features

- Extendable. Common tasks(Private too)
- Watch files for modifications
- Retry/Rerun tasks based on failures before giving up
- Retry/Rerun tasks based on failures before giving up
- Logging
- Success/Failure decision tree
- Run tasks asynchronously or synchronously
- Run tasks asynchronously or synchronously
- Autocomplete task names
- Static webserver
- Many more!
- Many more!

## Usage

Create a file named: `alfred.yml`
```

```yaml
say.hello:
summary: I will say hello!
usage: alfred say.hello
Expand Down Expand Up @@ -65,24 +71,30 @@ Then, anywhere in the top-level or child directories to the `alfred.yml` file:

`alfred blurt` will perform both tasks at the same time

# Quick Walkthrough
[![asciicast](https://asciinema.org/a/103711.png)](https://asciinema.org/a/103711)
## Quick Walkthrough

To see a comprehensive list of features and functionality please [RTFM](RTFM.md "additional documentation")

[For additional documentation, please refer to the GUIDE](GUIDE.md "additional documentation")
[![asciicast](https://asciinema.org/a/103711.png)](https://asciinema.org/a/103711)

## Example uses
* Monitor websites
* Setup/Update/Deploy projects in your dev env
* Simple Nagios, Jenkins, pingdom replacement
* Monitor crons(alert on failures, update endpoints etc ... )
* Watch for file modifications to run tests->builds

- Monitor websites
- Setup/Update/Deploy projects in your dev env
- Simple Nagios, Jenkins, pingdom replacement
- Monitor crons(alert on failures, update endpoints etc ... )
- Watch for file modifications to run tests->builds

## Tab completion

Copy the included `alfred.completion.sh` to `/etc/bash_completion.d/`, or source it in your `~/.profile` file.
Copy the included `alfred.completion.sh` to `/etc/bash_completion.d/`.

Or source it in your `~/.profile` file.

Or `alfred /self tab.completion`

## Testing

You might say I've cheated the testing route by only scraping the output. You'd be right.

"I live with a wizard. I cheat" ~ Mouse
"I live with a wizard. I cheat" ~ Mouse
File renamed without changes.
1 change: 1 addition & 0 deletions alfred.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tdd:
test:
summary: Testing ...
command: |
go install
go test -v
commit:
Expand Down
33 changes: 17 additions & 16 deletions alfred/alfred.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/fatih/color"
"github.com/kcmerrill/alfred/remote"
"github.com/kcmerrill/alfred/task"
"gopkg.in/yaml.v2"
)

Expand All @@ -32,7 +31,7 @@ type Alfred struct {
// Variables
Vars map[string]string `yaml:"alfred.vars"`
// All of the tasks parsed from the yaml file
Tasks map[string]*task.Task `yaml:",inline"`
Tasks map[string]*Task `yaml:",inline"`
// Alfred remotes(private/public repos)
remote *remote.Remote
// Originating directory
Expand All @@ -56,6 +55,8 @@ func New(args []string) {
// Grab the current directory and save if off
a.dir, _ = os.Getwd()

fmt.Println(args)

// Set our Arguments
a.args = args

Expand All @@ -69,7 +70,7 @@ func New(args []string) {
if !a.findTask() {
a.args = append(a.args[:1], append([]string{"default"}, a.args[1:]...)...)
if !a.findTask() {
say("ERROR", "Invalid task.")
say("ERROR", "Invalid taskkkkkkk.")
os.Exit(1)
}
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func (a *Alfred) findTask() bool {
return false
}
} else {
say(a.args[2], "invalid task.")
say(a.args[2], "Invalid taskk.")
return false
}
break
Expand All @@ -129,15 +130,15 @@ func (a *Alfred) findTask() bool {
func (a *Alfred) runTask(task string, args []string, formatted bool) bool {
// Verify again it's a valid task
if !a.isValidTask(task) {
say(task, "Invalid task.")
say(task, "Invalid task."+task+"--")
return false
}

// Infinite loop Used for the every command
for {
// Run our setup tasks
for _, s := range a.Tasks[task].SetupTasks() {
if !a.runTask(s, args, formatted) {
for _, taskDefinition := range a.Tasks[task].TaskGroup(a.Tasks[task].Setup, args) {
if !a.runTask(taskDefinition.Name, taskDefinition.Params, formatted) {
break
}
}
Expand Down Expand Up @@ -177,7 +178,7 @@ func (a *Alfred) runTask(task string, args []string, formatted bool) bool {
m, _ := regexp.Match(a.Tasks[task].Watch, []byte(path))
if m {
// If not a match ...
return errors.New("")
return errors.New("no matches")
}
}
return nil
Expand Down Expand Up @@ -248,8 +249,8 @@ func (a *Alfred) runTask(task string, args []string, formatted bool) bool {
fmt.Println(red("✘"), task)

// Failed? Lets run the failed tasks
for _, failed := range a.Tasks[task].FailedTasks() {
if !a.runTask(failed, args, formatted) {
for _, taskDefinition := range a.Tasks[task].TaskGroup(a.Tasks[task].Fail, args) {
if !a.runTask(taskDefinition.Name, taskDefinition.Params, formatted) {
break
}
}
Expand All @@ -274,26 +275,26 @@ func (a *Alfred) runTask(task string, args []string, formatted bool) bool {

var wg sync.WaitGroup
// Do we have any tasks we need to run in parallel?
for _, t := range a.Tasks[task].MultiTask() {
for _, taskDefinition := range a.Tasks[task].TaskGroup(a.Tasks[task].Multitask, args) {
wg.Add(1)
go func(t string, args []string) {
defer wg.Done()
a.runTask(t, args, true)
}(t, args)
}(taskDefinition.Name, taskDefinition.Params)
}
wg.Wait()

// Ok, we made it here ... Is this task a task group?
for _, t := range a.Tasks[task].TaskGroup() {
if !a.runTask(t, args, formatted) {
for _, taskDefinition := range a.Tasks[task].TaskGroup(a.Tasks[task].Tasks, args) {
if !a.runTask(taskDefinition.Name, taskDefinition.Params, formatted) {
break
}
}

// Woot! Lets run the ok tasks
if taskok {
for _, okTasks := range a.Tasks[task].OkTasks() {
if !a.runTask(okTasks, args, formatted) {
for _, taskDefinition := range a.Tasks[task].TaskGroup(a.Tasks[task].Ok, args) {
if !a.runTask(taskDefinition.Name, taskDefinition.Params, formatted) {
break
}
}
Expand Down
Loading

0 comments on commit 9a53ac5

Please sign in to comment.