Skip to content

Commit c97f9de

Browse files
authored
Merge pull request #5 from codetent/fix-order
fix dynamic file path loading
2 parents 2585a62 + df34390 commit c97f9de

15 files changed

Lines changed: 170 additions & 83 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ FROM golang:1.25.4-trixie
33
# Install basic dependencies
44
RUN apt update && \
55
apt install -y \
6-
git \
76
curl \
7+
git \
8+
tar \
89
&& \
910
rm -rf /var/lib/apt/lists/*
1011

1112
# Install task
12-
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d v3.36.0
13+
RUN sh -c "$(curl -L https://taskfile.dev/install.sh)" -- -d v3.36.0
1314

1415
# Install golangci-lint
15-
RUN sh -c "$(curl --location https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh)" -- v2.6.2
16+
RUN sh -c "$(curl -L https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh)" -- v2.6.2
17+
18+
# Install gotestsum
19+
RUN curl -L https://github.com/gotestyourself/gotestsum/releases/download/v1.13.0/gotestsum_1.13.0_linux_amd64.tar.gz -o gotestsum.tar.gz && \
20+
tar -xzf gotestsum.tar.gz -C /usr/local/bin gotestsum && \
21+
rm gotestsum.tar.gz
22+
23+
# Install jd
24+
RUN curl -L https://github.com/josephburnett/jd/releases/download/v2.3.0/jd-amd64-linux -o /usr/local/bin/jd && \
25+
chmod +x /usr/local/bin/jd

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"image": "ghcr.io/codetent/confless/dev:sha-382640a",
2+
"image": "ghcr.io/codetent/confless/dev:sha-6fd6dc8",
33
"runArgs": [
44
"--platform=linux/amd64"
55
],

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
check:
1414
runs-on: ubuntu-latest
1515
container:
16-
image: ghcr.io/codetent/confless/dev:sha-382640a
16+
image: ghcr.io/codetent/confless/dev:sha-6fd6dc8
1717
env:
1818
GOFLAGS: -buildvcs=false
1919
steps:

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Sources are applied in the following order (later sources override earlier ones)
7474
1. **Files** (in registration order)
7575
2. **Command-line flags**
7676
3. **Environment variables** (highest precedence)
77+
4. **Dynamically registered files**
7778

7879
### Files
7980

@@ -112,7 +113,9 @@ database:
112113
113114
You can mark a field in your configuration with the `confless:"file"` tag to automatically load it as a configuration file. This is useful for environment-specific configurations.
114115

115-
The format can be specified explicitly in the tag (`confless:"file,format=json"`) otherwise it defaults to JSON.
116+
The format can be specified explicitly in the tag (`confless:"file,format=yaml"`) otherwise it defaults to JSON.
117+
118+
Note that dynamically registered files are loaded at the end, while statically registered files are loaded first.
116119

117120
```go
118121
type Config struct {

Taskfile.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
version: '3'
22

3+
includes:
4+
examples:
5+
dir: examples
6+
taskfile: examples/Taskfile.yml
7+
38
tasks:
49
test:
510
cmds:
6-
- go test -v ./...
11+
- gotestsum --format testdox
12+
- task: examples:test
713

814
lint:
915
cmds:

confless.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ var (
66
defaultLoader = NewLoader()
77
)
88

9+
// Configure the default loader with the given options.
10+
// Note that reconfiguring the default loader will reset the registered sources.
11+
func Configure(opts ...loaderOption) {
12+
defaultLoader = NewLoader(opts...)
13+
}
14+
915
// Register an environment variable prefix to load.
1016
// Names are converted to dot-separated paths (e.g. "MY_FLAG" -> "my.flag").
1117
func RegisterEnv(pre string) {

example/config.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

example/main.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

example/other.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/Taskfile.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
3+
tasks:
4+
test:
5+
cmds:
6+
- cmd: |
7+
cd {{ .ITEM.dir }} &&
8+
{{ .ITEM.cmd }} | jd {{ .ITEM.expected }}
9+
for:
10+
- dir: simple
11+
cmd: >-
12+
APP_DATABASE_USERNAME=user
13+
APP_DATABASE_PASSWORD=pass
14+
go run main.go
15+
--debug
16+
--config=files/override.yaml
17+
expected: expected.json

0 commit comments

Comments
 (0)