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
27 changes: 17 additions & 10 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: CI

on:
push:
Expand All @@ -10,21 +10,28 @@ jobs:

test:
strategy:
fail-fast: false
matrix:
go_version: [ '1.14', '1.15', '1.16', '1.17' ]
# 1.18 is the module floor (go.mod); oldstable/stable track the two
# most recent Go releases.
go-version: [ '1.18', 'oldstable', 'stable' ]
os: [ 'ubuntu-latest', 'windows-latest', 'macOS-latest' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use GO ${{ matrix.go_version }}
uses: actions/setup-go@v2
- name: Use Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}
go-version: ${{ matrix.go-version }}

- name: Test GO ${{ matrix.go_version }}
- name: Test
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic

- name: Upload to codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go_version == '1.17' }}
run: bash <(curl -s https://codecov.io/bash)
- name: Upload coverage to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go-version == 'stable' }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt
fail_ci_if_error: false
73 changes: 73 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Changelog

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
While the major version is `0`, the public API may change in any release.

## [Unreleased]

### Added

- `CONTRIBUTING.md` describing setup, the test/lint workflow, code style, and the
commit/PR/release process.
- This `CHANGELOG.md`.

### Fixed

- CI is green again. The GitHub Actions workflow tested Go 1.14–1.17, which have
no `darwin/arm64` builds and so failed to install on the now-Apple-Silicon
`macOS-latest` runners, cancelling the whole matrix. The workflow now tests the
module's real floor (`1.18`) plus the two latest Go releases, sets
`fail-fast: false`, and upgrades to `actions/checkout@v4`,
`actions/setup-go@v5`, and `codecov/codecov-action@v5`.

### Changed

- Relicensed the project from the Apache License 2.0 to the MIT License.
- Reworked `README.md`: status badges, a tag reference table, the supported-type
list, an explicit default-precedence rule (CLI flag > `envVar` > `value` > zero
value), and a runnable example.

## [0.0.3] - 2022-11-08

### Added

- `uint` and `uint64` field types.

### Changed

- Converted the project to a Go module (`module github.com/memclutter/confparse`,
`go 1.18`).
- Replaced Travis CI with a GitHub Actions workflow running `go test ./... -race`
across a Go version matrix (1.14–1.17) on Linux, macOS, and Windows, and
uploading coverage to Codecov.
- Reworked the test suite into table-driven cases at 100% coverage, including the
default-value error paths for every supported type.

## [0.0.2] - 2018-10-08

### Added

- `int64` field type.

## [0.0.1] - 2018-09-25

First release of `confparse` — a declarative command-line argument parser for Go.

### Added

- `Parse(container interface{}) error`, which reflects over a pointer-to-struct
and registers each field as a standard-library `flag`.
- Struct tags `name` (flag name), `value` (string default), `usage` (help text),
and `envVar` (environment-variable fallback for the default).
- Supported field types: `string`, `int`, `bool`, and `time.Duration`.
- Environment extension: when a field's `envVar` variable is set and non-empty,
its value becomes the field's default.

[Unreleased]: https://github.com/memclutter/confparse/compare/v0.0.3...HEAD
[0.0.3]: https://github.com/memclutter/confparse/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/memclutter/confparse/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/memclutter/confparse/releases/tag/v0.0.1
</content>
89 changes: 89 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Contributing

Thanks for your interest in improving `confparse`. This document describes how to
set up the project, the conventions the codebase follows, and how to get a change
merged.

## Prerequisites

- Go 1.18 or newer (the module targets `go 1.18`).
- That is all — `confparse` has no runtime dependencies beyond the standard
library, and the test suite needs no external services.

## Getting started

```bash
git clone https://github.com/memclutter/confparse.git
cd confparse
go mod download
go test ./...
```

`confparse` is a library, not a binary: there is nothing to run on its own. The
quickest way to exercise a change is to add or adjust a case in `parse_test.go`.

## Development workflow

- Branch off `main` with a short-lived topic branch; keep one logical change per
pull request.
- Run the checks below before pushing; CI must be green before review.

```bash
go build ./... # compiles
go test ./... -race -coverprofile=cover.out # runs the suite with the race detector
gofmt -l . # must print nothing (formatting)
```

CI (`.github/workflows/go.yml`) runs `go test ./... -race` across a matrix of Go
versions and operating systems on every push and pull request, and uploads
coverage to Codecov. The suite is kept at 100% coverage — keep it there.

## Code style

- Format with `gofmt` / `goimports`; do not hand-format.
- Keep the public surface minimal: the package exposes a single function,
`Parse(container interface{}) error`. Treat it and the existing struct-tag
names (`name`, `value`, `usage`, `envVar`) as a stability contract.
- Wrap errors with context rather than returning bare errors where it adds
information.
- Prefer table-driven tests; every supported type and error path has a row in
`parse_test.go` — add one for anything you change.

## Adding a supported type

Supported field types are a contract. When adding one:

1. Add a `case *T:` to the type switch in `declareFlag` (`parse.go`), converting
the `value` string into `T` and registering the matching `flag.TVar`.
2. Add a conversion helper if the type needs one, mirroring the existing
`toInt` / `toUint` / `toTimeDuration` helpers (return the conversion error).
3. Add success and error-path rows to `parse_test.go`, and document the type in
`README.md`.

## Commit messages

This project uses [Conventional Commits](https://www.conventionalcommits.org/):

```
feat(parse): support float64 fields
fix(parse): return error on invalid uint default
docs(readme): document default precedence
```

Use `feat` / `fix` / `docs` / `refactor` / `test` / `chore` as appropriate; mark
breaking changes with a `!` or a `BREAKING CHANGE:` footer. Adding a type or tag
extends the public contract — call it out in the message.

## Pull requests

- Describe what changes and why; link any related issue.
- Keep the diff focused and the history readable.
- Update `README.md` and `CHANGELOG.md` (under `## [Unreleased]`) when your change
affects behaviour users can see.

## Releases

Releases follow [Semantic Versioning](https://semver.org/). While the major
version is `0`, the public API may change in any release. Maintainers cut releases
by tagging `vMAJOR.MINOR.PATCH` and publishing notes built from the changelog.
</content>
Loading
Loading