diff --git a/.ron/go.yaml b/.ron/go.yaml index 772ffa0..c1638cd 100644 --- a/.ron/go.yaml +++ b/.ron/go.yaml @@ -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 '-' '_' diff --git a/README.md b/README.md index 4ddc6c3..1368f9b 100644 --- a/README.md +++ b/README.md @@ -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/ +``` diff --git a/commands/template/template.go b/commands/template/template.go index 9401622..fbea5f6 100644 --- a/commands/template/template.go +++ b/commands/template/template.go @@ -1,4 +1,4 @@ -package ron +package template import ( "flag" diff --git a/commands/template/template_test.go b/commands/template/template_test.go index 0bc1871..7f2e852 100644 --- a/commands/template/template_test.go +++ b/commands/template/template_test.go @@ -1,4 +1,4 @@ -package ron +package template import ( "bytes" diff --git a/commands/upgrade/upgrade.go b/commands/upgrade/upgrade.go index bfa228a..08351a7 100644 --- a/commands/upgrade/upgrade.go +++ b/commands/upgrade/upgrade.go @@ -1,4 +1,4 @@ -package ron +package upgrade import ( "fmt" diff --git a/commands/upgrade/upgrade_test.go b/commands/upgrade/upgrade_test.go index c347128..4efc55b 100644 --- a/commands/upgrade/upgrade_test.go +++ b/commands/upgrade/upgrade_test.go @@ -1,4 +1,4 @@ -package ron +package upgrade import ( "bytes" diff --git a/commands/version/version.go b/commands/version/version.go index a13d59c..3323cf5 100644 --- a/commands/version/version.go +++ b/commands/version/version.go @@ -1,4 +1,4 @@ -package ron +package version import ( "fmt" diff --git a/commands/version/version_test.go b/commands/version/version_test.go index a705823..20e464c 100644 --- a/commands/version/version_test.go +++ b/commands/version/version_test.go @@ -1,4 +1,4 @@ -package ron +package version import ( "bytes" diff --git a/ron.yaml b/ron.yaml index b627340..a032ceb 100644 --- a/ron.yaml +++ b/ron.yaml @@ -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: diff --git a/version.go b/version.go index f5e68a5..0237402 100644 --- a/version.go +++ b/version.go @@ -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 = "" )