Skip to content

Commit

Permalink
add flags
Browse files Browse the repository at this point in the history
  • Loading branch information
do-i-need-a-username committed Nov 29, 2023
1 parent e2dd0fc commit b647411
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 40 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
38 changes: 0 additions & 38 deletions .github/workflows/go-ossf-slsa3-publish.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

# Go workspace file
go.work
bin/**
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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: [[email protected]]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit b647411

Please sign in to comment.