diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1c640c9 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..d719ef1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..1f2e45a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -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. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..0b73b24 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -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 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..01fffd3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..9587f9d --- /dev/null +++ b/.github/pull_request_template.md @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af69f7f..6d7a8f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 042ac1f..c8b81af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 ./... diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..57459e9 --- /dev/null +++ b/CHANGELOG.md @@ -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. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7f249b4 --- /dev/null +++ b/CONTRIBUTING.md @@ -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. diff --git a/README.md b/README.md index dd31a33..7606524 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,132 @@ +
+ # 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) + +
+ +--- -## 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 [--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 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..da34a11 --- /dev/null +++ b/SECURITY.md @@ -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. diff --git a/main.go b/main.go index e9a3387..dc6d7ce 100644 --- a/main.go +++ b/main.go @@ -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: @@ -29,6 +32,10 @@ Aliases: devkit yaml-to-json [file|-] devkit check-port +Flags: + -h, --help show this help + -v, --version print the devkit version + Use "-" or omit the file argument to read from standard input. ` @@ -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 diff --git a/main_test.go b/main_test.go index b5b134a..597bcec 100644 --- a/main_test.go +++ b/main_test.go @@ -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()) + } +}