Skip to content

Commit

Permalink
Merge pull request #9 from breml/add-mustache
Browse files Browse the repository at this point in the history
Add mustache
  • Loading branch information
breml authored Jul 9, 2021
2 parents f48df7a + 2927b7f commit 15df4bd
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 83 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: goreleaser

on:
push:
tags:
- 'v[0-9]*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 13 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ jobs:
test:
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
go-version: [1.15.x, 1.16.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
-
name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code

-
name: Checkout code
uses: actions/checkout@v2
- name: Test

-
name: Build
run: go build ./...

-
name: Test
run: go test -v -cover ./...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@

.idea/
*~

# Goreleaser
dist/
31 changes: 31 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- main: ./cmd/mustache
binary: mustache
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
skip: true
release:
github:
owner: breml
name: logstash-config
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# logstash-config : parser and abstract syntax tree for [Logstash](https://github.com/elastic/logstash) config files
# logstash-config : parser and abstract syntax tree for [Logstash](https://www.elastic.co/logstash/) config files

[![Test Status](https://github.com/breml/logstash-config/workflows/Test/badge.svg)](https://github.com/breml/logstash-config/actions?query=workflow%3ATest)
[![Go Report Card](https://goreportcard.com/badge/github.com/breml/logstash-config)](https://goreportcard.com/report/github.com/breml/logstash-config)\
[![GoDoc](https://godoc.org/github.com/breml/logstash-config?status.svg)](https://godoc.org/github.com/breml/logstash-config) [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
[![GoDoc](https://pkg.go.dev/badge/github.com/breml/logstash-config)](https://pkg.go.dev/github.com/breml/logstash-config) [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)

## Overview

The Go package config provides a ready to use parser for [Logstash](https://github.com/elastic/logstash) configuration files.
The Go package config provides a ready to use parser for Logstash ([github](https://github.com/elastic/logstash)) configuration files.

The basis of the grammar for the parsing of the Logstash configuration format is the original [Logstash Treetop grammar](https://github.com/elastic/logstash/blob/master/logstash-core/lib/logstash/config/grammar.treetop) which could be used with only minor changes.

Expand All @@ -22,10 +22,42 @@ go get -t github.com/breml/logstash-config/...

## Usage

### ls-config-check
### mustache

`cmd/ls-config-check` contains the source code for a small sample tool, which uses just allow to parse a given Logstash config file. If the file could be parsed successfully, the tool just exits with exit code `0`. If the parsing fails, the exit code is non zero and a error message, indicating the location, where the parsing failed, is printed.
`ls-config-check <logstash-config-file>` could be used instead if `bin/logstash -f <logstash-config-file> -t`, which is orders of magnitude faster 😃.
`mustache` is a command line tool that allows to syntax check, lint and format Logstash configuration files. The name of
the tool is inspired by the original Logstash Logo ([wooden character with an eye-catching mustache](https://www.elastic.co/de/blog/high-level-logstash-roadmap-is-published)).

The `check` command verifies the syntax of Logstash configuration files:

```shell
mustache check file.conf
```

The `lint` command checks for problems in Logstash configuration files.

The following checks are performed:

* Valid Logstash configuration file syntax
* No comments in exceptional places (these are comments, that are valid by the Logstash configuration file syntax, but
but are located in exceptional or uncommon locations)
* Precence of an `id` attribute for each plugin in the Logstash configuration

If the `--auto-fix-id` flag is passed, each plugin gets automatically an ID. Be aware, that this potentially reformats
the Logstash configuration files.

```shell
mustache lint --auto-fix-id file.conf
```

With the `format` command, mustache returns the provided configuration files in a standardized format (indentation,
location of comments). By default, the reformatted file is print to standard out. If the flag `--write-to-source`
is provided, the Logstash config files are reformatted in place.

```shell
mustache format --write-to-source file.conf
```

Use the `--help` flag to get more information about the usage of the tool.

## Rebuild parser

Expand Down
2 changes: 0 additions & 2 deletions cmd/ls-config-check/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions cmd/ls-config-check/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions cmd/ls-config-check/main.go

This file was deleted.

1 change: 1 addition & 0 deletions cmd/mustache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mustache
14 changes: 14 additions & 0 deletions cmd/mustache/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"github.com/breml/logstash-config/internal/app"
)

var Version = "(unknown)"

func main() {
exitCode := app.Execute(Version, os.Stdout, os.Stderr)
os.Exit(exitCode)
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ module github.com/breml/logstash-config
go 1.14

require (
github.com/hashicorp/go-multierror v1.1.0
github.com/kr/pretty v0.2.0 // indirect
github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.1.0
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.5.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading

0 comments on commit 15df4bd

Please sign in to comment.