Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework internals #654

Merged
merged 2 commits into from
Jan 17, 2021
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
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install age
run: |
git clone https://github.com/FiloSottile/age
cd age
go install ./cmd/...
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: go build ./...
- name: Run
run: go run . --version
run: |
go run . --version
go run ./chezmoi2 --version
- name: Test
run: go test -race ./...
test-release:
Expand Down
20 changes: 16 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ linters:
- exportloopref
- forbidigo
- gci
- gochecknoinits
- gocritic
- godot
- goerr113
Expand All @@ -28,8 +29,7 @@ linters:
- interfacer
- makezero
- misspell
- nakedret
- nolintlint
- paralleltest
- prealloc
- predeclared
- rowserrcheck
Expand All @@ -50,7 +50,6 @@ linters:
- exhaustivestruct
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocyclo
Expand All @@ -59,10 +58,11 @@ linters:
- gomnd
- lll
- maligned
- nakedret
- nestif
- nlreturn
- noctx
- paralleltest
- nolintlint # FIXME renable
- testpackage
- wrapcheck
- wsl
Expand All @@ -86,14 +86,26 @@ issues:
- linters:
- dupl
path: "secretpass.go"
- linters:
- nolintlint
- paralleltest
path: "^main_test.go$"
- linters:
- forbidigo
- gochecknoinits
- paralleltest
path: cmd/
- linters:
- gochecknoinits
path: internal/chezmoi/chezmoi_unix.go
- linters:
- forbidigo
- gosec
path: internal/cmd/
- linters:
- paralleltest
path: internal/
- linters:
- gosec
- scopelint
path: "_test\\.go"
50 changes: 50 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,56 @@ builds:
goarch: 386
- goos: linux
goarch: amd64
- id: chezmoi2-cgo-glibc
main: ./chezmoi2/main.go
env:
- CGO_ENABLED=1
goos:
- linux
goarch:
- amd64
- id: chezmoi2-cgo-musl
main: ./chezmoi2/main.go
env:
- CC=/usr/bin/musl-gcc
- CGO_ENABLED=1
goos:
- linux
goarch:
- amd64
ldflags:
- '-s'
- '-w'
- '-X main.version={{.Version}}'
- '-X main.commit={{.Commit}}'
- '-X main.date={{.Date}}'
- '-X main.builtBy=goreleaser'
- '-linkmode external'
- '--extldflags "-static"'
- id: chezmoi2-nocgo
main: ./chezmoi2/main.go
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- freebsd
- openbsd
- windows
goarch:
- 386
- amd64
- arm
- arm64
- ppc64
- ppc64le
goarm:
- ""
ignore:
- goos: darwin
goarch: 386
- goos: linux
goarch: amd64

archives:
- builds:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ build: build-darwin build-linux build-windows
.PHONY: build-darwin
build-darwin: generate
GOOS=darwin GOARCH=amd64 go build -o /dev/null .
GOOS=darwin GOARCH=amd64 go build -o /dev/null ./chezmoi2

.PHONY: build-linux
build-linux: generate
GOOS=linux GOARCH=amd64 go build -o /dev/null .
GOOS=linux GOARCH=amd64 go build -o /dev/null ./chezmoi2

.PHONY: build-windows
build-windows: generate
GOOS=windows GOARCH=amd64 go build -o /dev/null .
GOOS=windows GOARCH=amd64 go build -o /dev/null ./chezmoi2

.PHONY: run
run: generate
go run . --version
go run ./chezmoi2 --version

.PHONY: generate
generate:
Expand Down
65 changes: 65 additions & 0 deletions chezmoi2/cmd/addcmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/twpayne/chezmoi/chezmoi2/internal/chezmoi"
)

type addCmdConfig struct {
autoTemplate bool
empty bool
encrypt bool
exact bool
exists bool
follow bool
include *chezmoi.IncludeSet
recursive bool
template bool
}

func (c *Config) newAddCmd() *cobra.Command {
addCmd := &cobra.Command{
Use: "add targets...",
Aliases: []string{"manage"},
Short: "Add an existing file, directory, or symlink to the source state",
Long: mustLongHelp("add"),
Example: example("add"),
Args: cobra.MinimumNArgs(1),
RunE: c.makeRunEWithSourceState(c.runAddCmd),
Annotations: map[string]string{
modifiesSourceDirectory: "true",
persistentStateMode: persistentStateModeReadWrite,
requiresSourceDirectory: "true",
},
}

flags := addCmd.Flags()
flags.BoolVarP(&c.add.autoTemplate, "autotemplate", "a", c.add.autoTemplate, "auto generate the template when adding files as templates")
flags.BoolVarP(&c.add.empty, "empty", "e", c.add.empty, "add empty files")
flags.BoolVar(&c.add.encrypt, "encrypt", c.add.encrypt, "encrypt files")
flags.BoolVarP(&c.add.exact, "exact", "x", c.add.exact, "add directories exactly")
flags.BoolVar(&c.add.exists, "exists", c.add.exists, "add files that should exist, irrespective of their contents")
flags.BoolVarP(&c.add.follow, "follow", "f", c.add.follow, "add symlink targets instead of symlinks")
flags.BoolVarP(&c.add.recursive, "recursive", "r", c.add.recursive, "recursive")
flags.BoolVarP(&c.add.template, "template", "T", c.add.template, "add files as templates")

return addCmd
}

func (c *Config) runAddCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error {
destAbsPathInfos, err := c.destAbsPathInfos(sourceState, args, c.add.recursive, c.add.follow)
if err != nil {
return err
}

return sourceState.Add(c.sourceSystem, c.persistentState, c.destSystem, destAbsPathInfos, &chezmoi.AddOptions{
AutoTemplate: c.add.autoTemplate,
Empty: c.add.empty,
Encrypt: c.add.encrypt,
Exact: c.add.exact,
Exists: c.add.exists,
Include: c.add.include,
Template: c.add.template,
})
}
Loading