Skip to content

Commit

Permalink
feat: Make chezmoi's core functionality available as a Go module
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 26, 2022
1 parent 6c0d0b5 commit 8a84b31
Show file tree
Hide file tree
Showing 318 changed files with 133 additions and 134 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- 'assets/docker/**'
- 'assets/vagrant/**'
- 'go.*'
- 'internal/**'
- 'pkg/**'
codeql:
needs: changes
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
Expand Down Expand Up @@ -255,11 +255,11 @@ jobs:
- name: Test (umask 022)
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
run: |
go test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o022" -race ./...
go test -ldflags="-X github.com/twpayne/chezmoi/pkg/chezmoitest.umaskStr=0o022" -race ./...
- name: Test (umask 002)
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
run: |
go test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o002" -race ./...
go test -ldflags="-X github.com/twpayne/chezmoi/pkg/chezmoitest.umaskStr=0o002" -race ./...
- name: Test install.sh
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
run: |
Expand Down Expand Up @@ -466,7 +466,7 @@ jobs:
ignore: completions
- name: Whitespace
run: |
go run ./internal/cmds/lint-whitespace
go run ./pkg/cmds/lint-whitespace
- name: Typos
run: |
go install github.com/twpayne/findtypos@v0.0.1
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ issues:
- forbidigo
- gosec
- lll
path: ^internal/cmds/
path: ^pkg/cmds/
- linters:
- gosec
- lll
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ run:

.PHONY: test
test:
${GO} test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o022" ./...
${GO} test -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=0o002" ./...
${GO} test -ldflags="-X github.com/twpayne/chezmoi/pkg/chezmoitest.umaskStr=0o022" ./...
${GO} test -ldflags="-X github.com/twpayne/chezmoi/pkg/chezmoitest.umaskStr=0o002" ./...

.PHONY: test-docker
test-docker:
Expand All @@ -100,7 +100,7 @@ generate:
.PHONY: lint
lint: ensure-golangci-lint
./bin/golangci-lint run
${GO} run ./internal/cmds/lint-whitespace
${GO} run ./pkg/cmds/lint-whitespace

.PHONY: format
format: ensure-gofumpt
Expand Down
29 changes: 14 additions & 15 deletions assets/chezmoi.io/docs/developer/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ You can generate Go documentation for chezmoi's source code with `go doc`, for
example:

```console
$ go doc -all -u github.com/twpayne/chezmoi/v2/internal/chezmoi
$ go doc -all -u github.com/twpayne/chezmoi/v2/pkg/chezmoi
```

You can also [browse chezmoi's generated documentation
online](https://pkg.go.dev/github.com/twpayne/chezmoi/v2) but this only
includes exported symbols.
online](https://pkg.go.dev/github.com/twpayne/chezmoi/v2).

## Directory structure

The important directories in chezmoi are:

| Directory | Contents |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `assets/chezmoi.io/docs/` | The documentation single source of truth. Help text, examples, and the [chezmoi.io](https://chezmoi.io) website are generated from the files in this directory, particularly `docs/reference.md` |
| `internal/chezmoi/` | chezmoi's core functionality |
| `internal/cmd/` | Code for the `chezmoi` command |
| `internal/cmd/testdata/scripts/` | High-level tests of chezmoi's commands using [`testscript`](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) |
| Directory | Contents |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `assets/chezmoi.io/docs/` | The documentation single source of truth. Help text, examples, and the [chezmoi.io](https://chezmoi.io) website are generated from the files in this directory |
| `pkg/chezmoi/` | chezmoi's core functionality |
| `pkg/cmd/` | Code for the `chezmoi` command |
| `pkg/cmd/testdata/scripts/` | High-level tests of chezmoi's commands using [`testscript`](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript)

## Key concepts

Expand All @@ -37,7 +36,7 @@ represented directly in chezmoi's code.
chezmoi uses the generic term *entry* to describe something that it manages.
Entries can be files, directories, symlinks, scripts, amongst other things.

## `internal/chezmoi/` directory
## `pkg/chezmoi/` directory

All of chezmoi's interaction with the operating system is abstracted through
the `System` interface. A `System` includes functionality to read and write
Expand Down Expand Up @@ -100,10 +99,10 @@ its persistent state. chezmoi can then detect if a third party has updated a
target since chezmoi last wrote it by comparing the actual state entry in the
target state with the entry state in the persistent state.

## `internal/cmd/` directory
## `pkg/cmd/` directory

`internal/cmd/*cmd.go` contains the code for each individual command and
`internal/cmd/*templatefuncs.go` contain the template functions.
`pkg/cmd/*cmd.go` contains the code for each individual command and
`pkg/cmd/*templatefuncs.go` contain the template functions.

Commands are defined as methods on the `Config` struct. The `Config` struct is
large, containing all configuration values read from the config file, command
Expand Down Expand Up @@ -164,12 +163,12 @@ integration tests use the
[`github.com/stretchr/testify`](https://pkg.go.dev/github.com/stretchr/testify)
framework. End-to-end tests use
[`github.com/rogpeppe/go-internal/testscript`](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript)
with the test scripts themselves in `internal/cmd/testdata/scripts/*.txt`.
with the test scripts themselves in `pkg/cmd/testdata/scripts/*.txt`.

You can run individual end-to-end tests with

```console
$ go test ./internal/cmd -run=TestScript/<name>
$ go test ./pkg/cmd -run=TestScript/<name>
```

where `<name>` is the basename of file without the `.txt` extension.
Expand Down
22 changes: 0 additions & 22 deletions internal/cmd/cmd_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
//go:generate go run . completion fish -o completions/chezmoi.fish
//go:generate go run . completion powershell -o completions/chezmoi.ps1
//go:generate go run . completion zsh -o completions/chezmoi.zsh
//go:generate go run ./internal/cmds/generate-install.sh -o assets/scripts/install.sh
//go:generate go run ./pkg/cmds/generate-install.sh -o assets/scripts/install.sh

package main

import (
"os"

"github.com/twpayne/chezmoi/v2/internal/cmd"
"github.com/twpayne/chezmoi/v2/pkg/cmd"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestNewAbsPathFromExtPath(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"filippo.io/age/armor"
"go.uber.org/multierr"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// An AgeEncryption uses age for encryption and decryption. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestAgeEncryption(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/twpayne/chezmoi/v2/internal/archive"
"github.com/twpayne/chezmoi/v2/pkg/archive"
)

func TestArchiveReaderSystemTar(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

var _ PersistentState = &BoltPersistentState{}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestFQDNHostname(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/chezmoi/data_test.go → pkg/chezmoi/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestKernel(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chezmoi
import (
"github.com/rs/zerolog"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// A DebugEncryption logs all calls to an Encryption.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/rs/zerolog"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// A DebugSystem logs all calls to a System.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

var _ System = &DumpSystem{}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/rs/zerolog"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// An EntryStateType is an entry state type.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"go.uber.org/multierr"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// A GPGEncryption uses gpg for encryption and decryption. See https://gnupg.org/.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestGPGEncryption(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestPatternSet(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
vfs "github.com/twpayne/go-vfs/v4"
"go.uber.org/multierr"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// A RealSystemOption sets an option on a RealSystem.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

var _ System = &RealSystem{}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
vfs "github.com/twpayne/go-vfs/v4"
"go.uber.org/multierr"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// An ExternalType is a type of external source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
vfs "github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestSourceStateAdd(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rs/zerolog"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

// A SourceStateEntry represents the state of an entry in the source state.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestConcurrentWalkSourceDir(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
vfs "github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

func TestTargetStateEntryApply(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

var _ System = &TarWriterSystem{}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs/v4"

"github.com/twpayne/chezmoi/v2/internal/chezmoitest"
"github.com/twpayne/chezmoi/v2/pkg/chezmoitest"
)

var _ System = &ZIPWriterSystem{}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog"
)

var ageRecipientRx = regexp.MustCompile(`(?m)^Public key: ([0-9a-z]+)\s*$`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
// umaskStr is the umask used in tests represented as a string so it can be
// set with the
// -ldflags="-X github.com/twpayne/chezmoi/internal/chezmoitest.umaskStr=..."
// -ldflags="-X github.com/twpayne/chezmoi/pkg/chezmoitest.umaskStr=..."
// option to go build and go test.
umaskStr = "0o022"

Expand Down
Loading

0 comments on commit 8a84b31

Please sign in to comment.