Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe committed Jul 21, 2024
0 parents commit f4ae3c0
Show file tree
Hide file tree
Showing 20 changed files with 438 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true

[*.go]
indent_style = tab
insert_final_newline = false

[Makefile]
indent_style = tab
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build

on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Build
run: make builds
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint

on:
push:
branches:
- main
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Set up golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
cache: true
- name: Lint
run: make lint
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22
cache: true
- name: Build
run: make builds
- name: Release
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Test
run: make test-coverage
- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ./coverage.out
name: codecov-umbrella
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

/configurations
/shazam.yml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 mistweaver.co

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BIN_NAME=kulala-fmt

build-windows-64:
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-s -w -X 'github.com/mistweaverco/kulala-fmt/cmd/kulalafmt.VERSION=$(VERSION)'" -o dist/windows/$(BIN_NAME).exe main.go
build-linux-64:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-s -w -X 'github.com/mistweaverco/kulala-fmt/cmd/kulalafmt.VERSION=$(VERSION)'" -o dist/linux/$(BIN_NAME)-linux main.go
build-macos-arm64:
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-s -w -X 'github.com/mistweaverco/kulala-fmt/cmd/kulalafmt.VERSION=$(VERSION)'" -o dist/macos/$(BIN_NAME)-macos main.go

builds: build-linux-64 build-macos-arm64 build-windows-64

lint:
golangci-lint run

test:
if [ -n $(COLORS_ENABLED) ]; then gotest ./... ; else go test ./...; fi

test-coverage:
go test -race -covermode=atomic -coverprofile=coverage.out ./...

release:
gh release create --generate-notes v$(VERSION) dist/linux/$(BIN_NAME)-linux dist/macos/$(BIN_NAME)-macos dist/windows/$(BIN_NAME).exe

build-and-install-local-debug:
go build -ldflags "-X 'github.com/mistweaverco/kulala-fmt/cmd/kulalafmt.VERSION=development'" -o dist/$(BIN_NAME) main.go
sudo mv dist/$(BIN_NAME) /usr/bin/$(BIN_NAME)

run:
go run -ldflags "-X 'github.com/mistweaverco/kulala-fmt/cmd/kulalafmt.VERSION=development'" main.go
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div align="center">

![Kulala-fmt Logo](logo.svg)

# kulala-fmt

[![Go](https://img.shields.io/badge/Made%20with%20Go-00ADD8.svg?style=for-the-badge&logo=go&logoColor=ffffff)](https://golang.org)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/mistweaverco/kulala-fmt?style=for-the-badge)](https://github.com/mistweaverco/kulala-fmt/releases/latest)
[![Discord](https://img.shields.io/badge/discord-join-7289da?style=for-the-badge&logo=discord)](https://discord.gg/QyVQmfY4Rt)

[Install](#install)[Usage](#usage)

<p></p>

An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡.

<p></p>

</div>

## Install

Just grab the latest release:

- [Linux](https://github.com/mistweaverco/kulala-fmt/releases/download/latest/kulala-fmt-linux)
- [Mac](https://github.com/mistweaverco/kulala-fmt/releases/download/latest/kulala-fmt-macos)
- [Windows](https://github.com/mistweaverco/kulala-fmt/releases/download/latest/kulala-fmt.exe)

## Usage

Format all `.http` and `.rest` files in the current directory and its subdirectories:

```sh
kulala-fmt
```

Check if all `.http` and `.rest` files in the current directory and its subdirectories are formatted:

```sh
kulala-fmt --check
```
19 changes: 19 additions & 0 deletions cmd/kulalafmt/about.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kulalafmt

import (
"fmt"

"github.com/spf13/cobra"
)

var aboutCmd = &cobra.Command{
Use: "about",
Short: "Shows information about kulala-fmt",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Made with ❤️ by Marco Kellershoff - https://gorilla.moe")
},
}

func init() {
rootCmd.AddCommand(aboutCmd)
}
36 changes: 36 additions & 0 deletions cmd/kulalafmt/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kulalafmt

import (
"os"

"github.com/charmbracelet/log"
"github.com/mistweaverco/kulala-fmt/internal/config"
"github.com/mistweaverco/kulala-fmt/internal/parser"
"github.com/spf13/cobra"
)

var cfg = config.NewConfig(config.Config{})

var rootCmd = &cobra.Command{
Use: "kulala-fmt",
Short: "An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡.",
Long: "Formats and lints .http and .rest files in the current directory and subdirectories.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Info("Starting kulala-fmt 🦄", "version", VERSION)
parser.Start(cfg.GetConfigFlags())
}
},
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
rootCmd.PersistentFlags().BoolVar(&cfg.Flags.DryRun, "dry-run", false, "dry run")
rootCmd.PersistentFlags().BoolVar(&cfg.Flags.Check, "check", false, "check")
}
22 changes: 22 additions & 0 deletions cmd/kulalafmt/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kulalafmt

import (
"runtime"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var VERSION string

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of kulala-fmt",
Run: func(cmd *cobra.Command, args []string) {
log.Info("Version", runtime.GOOS, VERSION)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
2 changes: 2 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
24 changes: 24 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/mistweaverco/kulala-fmt

go 1.22

require (
github.com/charmbracelet/log v0.4.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.20.0 // indirect
)
Loading

0 comments on commit f4ae3c0

Please sign in to comment.