Skip to content

Commit

Permalink
Updates the README.md with an example of extending
Browse files Browse the repository at this point in the history
  • Loading branch information
pkaradimas committed Nov 10, 2017
1 parent e6462ef commit 6d5d3ed
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .ron/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envs:
- APP: go
- ARCH: amd64
- UNAME: +uname | tr '[:upper:]' '[:lower:]'
- GO_VERSION: 1.8
- GO_VERSION: 1.9.2
- TAG: v0.0.1
- RELEASES: linux darwin windows
- PACKAGE_VERSION: +git describe --always --dirty --tags | tr '-' '_'
Expand Down
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,130 @@ or download from [releases](https://github.com/upsight/ron/releases)
### Testing

$ ron t go:test

### Extending

To extend or customize ron, you can either fork the repo, or vendor it and overwrite the target/default.yaml
file and add custom commands.

The vendoring approach may look something like this:

1. Add vendor/github.com/upsight/ron to your project with whatever package manager you choose (dep, glide, etc.)

2. Create a new folder for your custom commands ./commands/commandname/commandname.go

```go
package commandname

import (
"fmt"
"io"
)

// Command ...
type Command struct {
Name string
W io.Writer
WErr io.Writer
AppName string
AppVersion string
GitCommit string
}

// Run ...
func (c *Command) Run(args []string) (int, error) {
fmt.Fprintln(c.W, c.AppName, c.AppVersion, c.GitCommit)
return 0, nil
}

// Key returns the commands name for sorting.
func (c *Command) Key() string {
return c.Name
}

// Aliases are the aliases and name for the command. For instance
// a command can have a long form and short form.
func (c *Command) Aliases() map[string]struct{} {
return map[string]struct{}{
"someothername": struct{}{},
}
}

// Description is what is printed in Usage.
func (c *Command) Description() string {
return "My command."
}
```

3. Create a custom cmd/ron/main.go and add all of your commands.

```golang
package main

import (
"log"
"os"

"mygitrepo.com/ron/commands/commandname"

"github.com/upsight/ron"
"github.com/upsight/ron/color"
)

func main() {
c := ron.NewDefaultCommander(os.Stdout, os.Stderr)
c.Add(&commandname.Command{AppName: ron.AppName, Name: "project", W: os.Stdout, WErr: os.Stderr})
status, err := ron.Run(c, os.Args[1:])
if err != nil {
hostname, _ := os.Hostname()
log.Println(hostname, color.Red(err.Error()))
}
os.Exit(status)
}
```

4. Optionally overwrite ./vendor/github.com/upsight/ron/target/default.yaml to have custom targets.

This can be done in a target or manually.

```bash
touch default.yaml
cp default.yaml vendor/$RONREPO/target/default.yaml
```

5. Create a ./ron.yaml file with instructions on how to put it all together.

```yaml
{{$path := "export PATH=$GOPATH/bin:$PATH"}}
envs:
- APP: ron
- ARCH: amd64
- PACKAGE_VERSION: +echo `git describe --tags`.`git rev-parse HEAD`
- REPO: myrepo.com/ron
- RONREPO: github.com/upsight/ron
- UNAME: +uname | tr '[:upper:]' '[:lower:]'
- VERSION: 1.4.0
- TAG: v${VERSION}
targets:
prep:
description: Compile the default yaml asset to a go file.
cmd: |
go install ./vendor/github.com/jteeuwen/go-bindata/go-bindata || go get -u github.com/jteeuwen/go-bindata/...
cp default.yaml vendor/$RONREPO/target/default.yaml
cd vendor/$RONREPO/target
go-bindata -o default.go -pkg=target default.yaml
build:
description: Compile a binary to ./bin/${UNAME}_${ARCH}
before:
- go:prep
cmd: |
{{$path}}
mkdir -p bin/${UNAME}_${ARCH}
GOARCH=$ARCH GOOS=$UNAME go build -o bin/${UNAME}_${ARCH}/${APP}-${UNAME}-${TAG} -ldflags "-X $REPO/vendor/$RONREPO.GitCommit=$PACKAGE_VERSION -X $REPO/vendor/$RONREPO.AppVersion=$TAG -X $REPO/vendor/$RONREPO.AppName=$APP" cmd/ron/*.go
```
6. Run the build
```bash
ron t ron:build && ls bin/
```
2 changes: 1 addition & 1 deletion commands/template/template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package template

import (
"flag"
Expand Down
2 changes: 1 addition & 1 deletion commands/template/template_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package template

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion commands/upgrade/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package upgrade

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion commands/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package upgrade

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion commands/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package version

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion commands/version/version_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ron
package version

import (
"bytes"
Expand Down
3 changes: 2 additions & 1 deletion ron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ targets:
- prep
- build
cmd: |
go install $REPO/cmd/$APP
cp bin/${UNAME}_${ARCH}/$APP-${UNAME}-$TAG $GOPATH/bin/ron
build:
description: Compile a binary to ./bin/${UNAME}_${ARCH}
before:
- prep
cmd: |
set -x
mkdir -p bin/${UNAME}_${ARCH}
GOARCH=$ARCH GOOS=$UNAME go build -o bin/${UNAME}_${ARCH}/$APP-${UNAME}-$TAG -ldflags "-X $REPO.GitCommit=$PACKAGE_VERSION -X $REPO.AppVersion=$TAG -X $REPO.AppName=$APP" cmd/$APP/*.go
build_all:
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ var (
// AppVersion the application version.
AppVersion = "0.0.1"
// GitCommit is the git hash for the current commit.
GitCommit = "53a7de4612c36b4cf36a9059b5dfa66fbc2639f9"
GitCommit = ""
)

0 comments on commit 6d5d3ed

Please sign in to comment.