Skip to content

Commit

Permalink
V2.0.0 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien authored Sep 27, 2017
1 parent ff3b514 commit ba41e3c
Show file tree
Hide file tree
Showing 924 changed files with 274,360 additions and 234 deletions.
6 changes: 3 additions & 3 deletions .assets/tests/orbit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
commands:
- use: "explorer"
run:
- glide
- dep status
- use: "sputnik"
run:
- glide
- dep status
- use: "challenger"
run:
- crash
- faildep status
6 changes: 2 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ find below useful information about how to contribute to the Orbit project.
### Install from sources

1. Fork this repository
2. Clone it to your local GO environment (requires *Go* >= 1.9)
3. Install the package manager *Glide*: `go get github.com/Masterminds/glide`
4. Install vendor dependencies: `glide install`
2. Clone it to your local Go environment (requires *Go* >= 1.9)
5. Install the latest Orbit release
6. Install lint dependencies by running `orbit run lint-install`
6. Install dependencies by running `orbit run install`

### Working with git

Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Explain the **motivation** for making this change. What existing problem does th

Demonstrate the code is solid. Example: The exact commands you ran and their output.

<!-- Make sure tests pass on both Travis and Circle CI. -->
<!-- Make sure tests pass on both Travis and AppVeyor. -->

**Closing issues**

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
dist
vendor
orbit
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.8.3
- 1.9
- tip

matrix:
Expand All @@ -10,10 +10,10 @@ matrix:
fast_finish: true

install:
- go get github.com/Masterminds/glide
- glide install
- go version
- go env
- go install
- orbit run lint-install
- orbit run install

script:
- orbit run lint
Expand Down
93 changes: 93 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/joho/godotenv"
version = "1.2.0"

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.3"

[[constraint]]
branch = "master"
name = "github.com/spf13/cobra"

[[constraint]]
branch = "v2"
name = "gopkg.in/yaml.v2"

[[constraint]]
name = "github.com/Masterminds/sprig"
version = "2.13.0"
52 changes: 34 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ The [Go documentation](https://golang.org/pkg/text/template/) and the
a lot of features that aren't mentioned here. Don't hesitate to take a look
at these links to understand the *Go* template engine! :smiley:

Also, Orbit provides [Sprig](http://masterminds.github.io/sprig/) library
and two custom functions:

* `os` which returns the current OS name at runtime (you may find all available names in the
[official documentation](https://golang.org/doc/install/source#environment)).
* `debug` which returns `true` if the `-d --debug` flag has been past to Orbit.

### Command description

#### Base
Expand Down Expand Up @@ -136,9 +143,9 @@ orbit generate [...] -r key_1=value_1;key_2=value_2

Your data will be accessible in your template through `{{ .RawData.my_key }}`.

##### `-s --silent`
##### `-d --debug`

Disables the notifications.
Displays a detailed output.

### Basic example

Expand Down Expand Up @@ -208,19 +215,22 @@ your Orbit commands:

```yaml
commands:
- use: "my_first_command"
- use: my_first_command
short: My first command short description
run:
- command [args]
- command [args]
- ...
- use: "my_second_command"
- use: my_second_command
short: My second command short description
run:
- command [args]
- command [args]
- ...
```
* the `use` attribute is the name of your Orbit command.
* the `short` attribute is optional and is displayed when running `orbit run`
* the `run` attribute is the stack of external commands to run.
* an external command is a binary which is available in your `$PATH`.

Expand All @@ -242,18 +252,26 @@ For example, if you need to run a platform specific script, you may write:

```yaml
commands:
- use: "script"
- use: script
run:
{{ if ne .Os "windows" }}
- /bin/bash my_script.sh
{{ if ne "windows" os }}
- /bin/sh -c my_script.sh
{{ else }}
- cmd.exe /c .\my_script.bat
{{ end }}
```

As you can see, Orbit provides the OS name at runtime with `{{ .Os }}`
(you may find all available names in the
[official documentation](https://golang.org/doc/install/source#environment) - `$GOOS` column).
Last but not least, you're also able to write complex commands:

```yaml
commands:
- use: complex
run:
- /bin/sh -c "ls -all | grep orbit"
```

Notice that the arguments are wrapped with `"`. You may also wrap them
using `` ` `` or `'`.

##### `-v --values`

Expand All @@ -273,22 +291,22 @@ The flag `-r` allows you to specify data directly from the CLI.

It works the same as the `-r` flag from the `generate` command.

##### `-s --silent`
##### `-d --debug`

Disables the notifications.
Displays a detailed output.

### Basic example

Let's create our simple configuration file `orbit.yml`:

```yaml
commands:
- use: "os"
- use: os
run:
{{ if ne .Os "windows" }}
- echo Current OS is {{ .Os }}
{{ if ne "windows" os }}
- echo Current OS is {{ os }}
{{ else }}
- cmd.exe /c echo Current OS is {{ .Os }}
- cmd.exe /c echo Current OS is {{ os }}
{( end }}
```

Expand All @@ -301,8 +319,6 @@ orbit run os
This command will print something like:

```
[i] starting Orbit command "os"
[i] running "echo Current OS is darwin"
Current OS is darwin
```

Expand Down
8 changes: 3 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ matrix:

install:
- rmdir c:\go /s /q
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.9rc2.windows-amd64.zip
- 7z x go1.9rc2.windows-amd64.zip -y -oC:\ > NUL
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.9.windows-amd64.zip
- 7z x go1.9.windows-amd64.zip -y -oC:\ > NUL
- set PATH=%GOPATH%\bin;%PATH%
- go version
- go env
- go get github.com/Masterminds/glide
- glide install
- go install
- orbit run lint-install
- orbit run install

build: off

Expand Down
19 changes: 4 additions & 15 deletions commands/generate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package commands

import (
"fmt"

"github.com/gulien/orbit/context"
"github.com/gulien/orbit/generator"

Expand All @@ -20,6 +18,7 @@ var (
generateCmd = &cobra.Command{
Use: "generate",
Short: "Generates a file according to a template",
Long: "Generates a file according to a template.",
SilenceUsage: true,
SilenceErrors: true,
RunE: generate,
Expand All @@ -46,21 +45,11 @@ func generate(cmd *cobra.Command, args []string) error {
}

// then retrieves the data from the template file.
gen := generator.NewOrbitGenerator(ctx)
data, err := gen.Parse()
g := generator.NewOrbitGenerator(ctx)
data, err := g.Parse()
if err != nil {
return err
}

// if an output file has been given, writes the result into it.
if outputFilePath != "" {
if err := gen.WriteOutputFile(outputFilePath, data); err != nil {
return err
}
} else {
// ok, no output file given, let's print the result to Stdout.
fmt.Println(string(data.Bytes()))
}

return nil
return g.Output(outputFilePath, data)
}
Loading

0 comments on commit ba41e3c

Please sign in to comment.