Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.go]
indent_style = tab

[*.{yml,yaml,md}]
indent_style = space
indent_size = 2
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Bug report
description: Something does not work as expected
labels: [bug]
body:
- type: textarea
id: what
attributes:
label: What happened?
description: Include the exact command you ran and its output.
render: shell
validations:
required: true
- type: textarea
id: expected
attributes:
label: What did you expect?
validations:
required: true
- type: input
id: version
attributes:
label: devkit version
description: Output of `devkit --version`
validations:
required: true
- type: dropdown
id: os
attributes:
label: Operating system
options: [Linux, macOS, Windows, Other]
validations:
required: true
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Security vulnerability
url: https://github.com/hamrezoffic-source/devkit/security/advisories/new
about: Please report security problems privately.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Feature request
description: Suggest a new command or improvement
labels: [enhancement]
body:
- type: textarea
id: problem
attributes:
label: What problem would this solve?
validations:
required: true
- type: textarea
id: proposal
attributes:
label: Proposed command or behavior
description: Example usage is very helpful.
render: shell
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## What does this change?

## Why?

## Checklist

- [ ] `gofmt -l .` prints nothing
- [ ] `go vet ./...` and `go test ./...` pass
- [ ] Tests added or updated
- [ ] README / CHANGELOG updated if behavior changed
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
ext=""
if [ "${GOOS}" = "windows" ]; then ext=".exe"; fi
mkdir -p dist
go build -trimpath -ldflags="-s -w" -o "dist/devkit-${GOOS}-${GOARCH}${ext}" .
go build -trimpath -ldflags="-s -w -X main.version=${GITHUB_REF_NAME}" -o "dist/devkit-${GOOS}-${GOARCH}${ext}" .
- uses: actions/upload-artifact@v4
with:
name: devkit-${{ matrix.goos }}-${{ matrix.goarch }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
- name: Format check
run: test -z "$(gofmt -l .)" || (gofmt -l . && exit 1)
if: runner.os != 'Windows'
- name: Vet
run: go vet ./...
- name: Test
run: go test ./...
run: go test -cover ./...
- name: Build
run: go build ./...
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project are documented here.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project uses [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added
- `devkit --version` / `-v`, set at build time from the release tag.
- `go vet` and coverage reporting in CI.
- Contributing guide, security policy, issue and pull request templates.

## [0.1.0] - 2026-11-23

### Added
- `json format`, `json to-yaml`, `yaml to-json` and `port check` commands.
- Cross-platform release builds for Linux, macOS and Windows (amd64, arm64).

### Fixed
- JSON to YAML no longer turns numbers into quoted strings.
- macOS CI builds with current stable Go.
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contributing to devkit

Thanks for taking the time to contribute.

## Getting started

1. Fork the repository and create a branch from `main`.
2. Install Go 1.22 or newer.
3. Make your change and add tests for it.
4. Run the checks below.
5. Open a pull request that explains what changed and why.

## Checks

All of these must pass before a pull request is merged (CI runs them on Linux, macOS and Windows):

```sh
gofmt -l . # must print nothing
go vet ./...
go test -cover ./...
go build ./...
```

## Guidelines

- Keep commands pipe-friendly: read from a file or standard input, write results to standard output, errors to standard error.
- Avoid new dependencies unless they are clearly worth it.
- Prefer table-driven tests.
- Use clear commit messages in the imperative mood, for example `Add sha256 command`.
- Update `README.md` and `CHANGELOG.md` when behavior changes.

## Reporting bugs and requesting features

Use the issue templates. For security problems, see [SECURITY.md](SECURITY.md) instead of opening a public issue.
133 changes: 104 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,132 @@
<div align="center">

# devkit

`devkit` is a fast, portable developer toolkit for formatting JSON, converting
between JSON and YAML, and checking TCP ports.
**A fast, portable, single-binary toolkit for everyday developer chores.**

Format JSON · Convert JSON ⇄ YAML · Check TCP ports

[![Test](https://github.com/hamrezoffic-source/devkit/actions/workflows/test.yml/badge.svg)](https://github.com/hamrezoffic-source/devkit/actions/workflows/test.yml)
[![Release](https://img.shields.io/github/v/release/hamrezoffic-source/devkit?sort=semver)](https://github.com/hamrezoffic-source/devkit/releases)
[![Go version](https://img.shields.io/github/go-mod/go-version/hamrezoffic-source/devkit)](go.mod)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

</div>

---

## Install
## Why devkit?

Download a binary for Windows, Linux, or macOS from the GitHub Releases page,
or build it from source:
- **One binary, no runtime.** Written in Go, statically built for Linux, macOS and Windows (amd64 and arm64).
- **Correct by default.** Large integers stay exact, numbers keep their type across JSON ⇄ YAML, duplicate YAML keys are rejected.
- **Pipe-friendly.** Every command reads a file or standard input and writes clean output to standard output.
- **Script-friendly exit codes.** `0` on success, `1` on any error.

## Installation

**Pre-built binaries:** download the file for your platform from the [Releases page](https://github.com/hamrezoffic-source/devkit/releases).

**With Go (1.22+):**

```sh
go build -o devkit .
go install github.com/hamrezoffic-source/devkit@latest
```

## JSON
**From source:**

Format JSON from a file or standard input:
```sh
git clone https://github.com/hamrezoffic-source/devkit.git
cd devkit
go build -o devkit .
```

Check the installation:

```sh
devkit json format input.json
cat input.json | devkit json format -
devkit format input.json
devkit --version
```

Convert JSON to YAML:
## Quick start

```sh
devkit json to-yaml input.json
cat input.json | devkit json-to-yaml -
# Pretty-print JSON
echo '{"name":"devkit","tags":["go","cli"]}' | devkit json format

# JSON -> YAML
devkit json to-yaml config.json > config.yaml

# YAML -> JSON
devkit yaml to-json config.yaml

# Is the port open?
devkit port check example.com 443
```

Large JSON integers are preserved without floating-point rounding.
## Commands

| Command | Description | Short alias |
| --- | --- | --- |
| `devkit json format [file\|-]` | Pretty-print JSON with 2-space indentation | `devkit format` |
| `devkit json to-yaml [file\|-]` | Convert JSON to YAML | `devkit json-to-yaml` |
| `devkit yaml to-json [file\|-]` | Convert YAML to formatted JSON | `devkit yaml-to-json` |
| `devkit port check <host> <port> [--timeout s]` | Test whether a TCP port accepts connections | `devkit check-port` |
| `devkit --version` | Print the version | `devkit -v` |
| `devkit --help` | Show usage | `devkit -h` |

## YAML
Omit the file argument, or pass `-`, to read from standard input.

Convert YAML to formatted JSON:
### JSON

```sh
devkit yaml to-json input.yaml
cat input.yaml | devkit yaml-to-json -
devkit json format input.json
cat input.json | devkit json format -
```

Empty input converts to `null`. Multiple YAML documents become a JSON array.
YAML mapping keys must be strings, duplicate keys are rejected, and non-finite
numbers cannot be represented by JSON.
Large integers such as `9007199254740993` are preserved without floating-point rounding. Input containing more than one JSON value is rejected.

## TCP ports
### JSON ⇄ YAML

Check whether a TCP port accepts connections:
```console
$ echo '{"port":8080,"debug":true,"name":"api"}' | devkit json to-yaml
debug: true
name: api
port: 8080
```

```sh
devkit port check example.com 443
devkit port check 127.0.0.1 8080 --timeout 5
devkit check-port example.com 443
- Numbers, booleans and `null` keep their types in both directions.
- Empty YAML input converts to `null`.
- Multiple YAML documents (`---`) become a JSON array.
- YAML keys must be strings; duplicate keys and non-finite numbers (`.inf`, `.nan`) are rejected because JSON cannot represent them.

### TCP port check

```console
$ devkit port check example.com 443
open
$ devkit port check 127.0.0.1 9 --timeout 1
closed
error: dial tcp 127.0.0.1:9: connect: connection refused
```

The command prints `open` on success and exits with a non-zero status on failure.
The default timeout is 3 seconds.

## Roadmap

- [x] JSON formatting and JSON ⇄ YAML conversion
- [x] TCP port check
- [x] `--version` flag and cross-platform releases
- [ ] Split into `cmd/` and `internal/` packages
- [ ] Hashing (`sha256`, `sha1`, `md5`), Base64, UUID, JWT decode, Unix timestamps
- [ ] Concurrent multi-port scan (`80,443,8000-8010`)
- [ ] Colored output with `NO_COLOR` support
- [ ] GoReleaser, Homebrew and Scoop packages

Ideas and feedback are welcome in [Issues](https://github.com/hamrezoffic-source/devkit/issues).

## Contributing

Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request.

## License

[MIT](LICENSE) © hamrezoffic-source
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Supported versions

Only the latest release receives security fixes.

## Reporting a vulnerability

Please do **not** open a public issue for security problems.
Report them privately through [GitHub Security Advisories](https://github.com/hamrezoffic-source/devkit/security/advisories/new).
You should receive a response within 7 days.
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"gopkg.in/yaml.v3"
)

// version is set at build time with -ldflags "-X main.version=v1.2.3".
var version = "dev"

const usage = `devkit - a fast, portable developer toolkit

Usage:
Expand All @@ -29,6 +32,10 @@ Aliases:
devkit yaml-to-json [file|-]
devkit check-port <host> <port>

Flags:
-h, --help show this help
-v, --version print the devkit version

Use "-" or omit the file argument to read from standard input.
`

Expand Down Expand Up @@ -278,6 +285,9 @@ func run(args []string) error {
}

switch args[0] {
case "-v", "--version", "version":
fmt.Printf("devkit %s\n", version)
return nil
case "-h", "--help", "help":
fmt.Print(usage)
return nil
Expand Down
20 changes: 20 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,23 @@ func TestJSONToYAMLKeepsNumberTypes(t *testing.T) {
t.Fatalf("round trip changed data:\n got %s\nwant %s", back, want)
}
}

func TestVersionFlag(t *testing.T) {
old := os.Stdout
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = w
runErr := run([]string{"--version"})
w.Close()
os.Stdout = old
if runErr != nil {
t.Fatalf("run(--version) error = %v", runErr)
}
var buf bytes.Buffer
buf.ReadFrom(r)
if !strings.HasPrefix(buf.String(), "devkit ") {
t.Fatalf("run(--version) printed %q", buf.String())
}
}
Loading