From b647411bee7ef05574b67b6656817a40896d2243 Mon Sep 17 00:00:00 2001 From: do-i-need-a-username <> Date: Wed, 29 Nov 2023 15:05:46 +1100 Subject: [PATCH] add flags --- .editorconfig | 16 +++++++++ .github/workflows/go-ossf-slsa3-publish.yml | 38 --------------------- .github/workflows/release.yml | 38 +++++++++++++++++++++ .gitignore | 1 + .pre-commit-config.yaml | 20 +++++++++++ README.md | 17 +++++++++ main.go | 12 +++++-- 7 files changed, 102 insertions(+), 40 deletions(-) create mode 100644 .editorconfig delete mode 100644 .github/workflows/go-ossf-slsa3-publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 .pre-commit-config.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6378052 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab + +[*.yaml, *.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/go-ossf-slsa3-publish.yml b/.github/workflows/go-ossf-slsa3-publish.yml deleted file mode 100644 index e3530d2..0000000 --- a/.github/workflows/go-ossf-slsa3-publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow lets you compile your Go project using a SLSA3 compliant builder. -# This workflow will generate a so-called "provenance" file describing the steps -# that were performed to generate the final binary. -# The project is an initiative of the OpenSSF (openssf.org) and is developed at -# https://github.com/slsa-framework/slsa-github-generator. -# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier. -# For more information about SLSA and how it improves the supply-chain, visit slsa.dev. - -name: SLSA Go releaser -on: - workflow_dispatch: - release: - types: [created] - -permissions: read-all - -jobs: - # ======================================================================================================================================== - # Prerequesite: Create a .slsa-goreleaser.yml in the root directory of your project. - # See format in https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/go/README.md#configuration-file - #========================================================================================================================================= - build: - permissions: - id-token: write # To sign. - contents: write # To upload release assets. - actions: read # To read workflow path. - uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.4.0 - with: - go-version: 1.21 - # ============================================================================================================= - # Optional: For more options, see https://github.com/slsa-framework/slsa-github-generator#golang-projects - # ============================================================================================================= - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7ddef92 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +# .github/workflows/release.yml +name: goreleaser + +on: + push: + # run only against tags + tags: + - "*" + +permissions: + contents: write + # packages: write + # issues: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v4 + with: + go-version: stable + # More assembly might be required: Docker logins, GPG, etc. + # It all depends on your needs. + - uses: goreleaser/goreleaser-action@v5 + with: + # either 'goreleaser' (default) or 'goreleaser-pro': + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' + # distribution: + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.gitignore b/.gitignore index 3b735ec..14d287f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ # Go workspace file go.work +bin/** diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e3657eb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-fmt + - id: go-vet + - id: go-lint + - id: go-imports + # - id: go-cyclo + # args: [-over=15] + # - id: golangci-lint + # additional_dependencies: [golangci-lint@v1.42.1] diff --git a/README.md b/README.md index 75631a4..f358c35 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # j2ndj # +[![goreleaser](https://github.com/do-i-need-a-username/j2ndj/actions/workflows/release.yml/badge.svg)](https://github.com/do-i-need-a-username/j2ndj/actions/workflows/release.yml) +[![Go Report Card](https://goreportcard.com/badge/github.com/do-i-need-a-username/j2ndj)](https://goreportcard.com/report/github.com/do-i-need-a-username/j2ndj) +[![codecov](https://codecov.io/gh/do-i-need-a-username/j2ndj/branch/main/graph/badge.svg?token=ZQZQZQZQZQ)](https://codecov.io/gh/do-i-need-a-username/j2ndj) +[![Go Reference](https://pkg.go.dev/badge/github.com/do-i-need-a-username/j2ndj.svg)](https://pkg.go.dev/github.com/do-i-need-a-username/j2ndj) + Converts a json file to [ndjson](https://ndjson.org/) file. (New Line Delimited JSON) + +## Installation ## + +```bash +# Install go +go install github.com/do-i-need-a-username/j2ndj@latest +# fins install path +which j2ndj +/Users/myuser/go/bin/j2ndj +# Run the command +/Users/myuser/go/bin/j2ndj -input /tmp/logs.json -output /tmp/logs.ndjson +``` diff --git a/main.go b/main.go index f72bf3a..6498387 100644 --- a/main.go +++ b/main.go @@ -12,11 +12,19 @@ import ( func main() { input := flag.String("input", "", "Input JSON file") - output := flag.String("output", "", "Output file") + output := flag.String("output", "", "Output file. Uses input with extention .ndjson if not provided") + + flag.Usage = func() { + fmt.Printf("Usage of %s:\n", os.Args[0]) + fmt.Println("Converts a json file to a New Line Delimited JSON (ndjson) file.") + fmt.Println("Flags:") + flag.PrintDefaults() + } + flag.Parse() if *input == "" { - fmt.Println("Please provide an input json file using the -input flag.") + flag.Usage() os.Exit(1) }