diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f1b27a3..5dfa50d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,17 +13,47 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: wagoid/commitlint-github-action@v4 - with: - firstParent: true - golangci: - name: lint + + - uses: wagoid/commitlint-github-action@v6 + + golangci-lint: + needs: commit_lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Run golangci-lint uses: golangci/golangci-lint-action@v6 with: version: latest only-new-issues: false args: --timeout 2m --config .golangci.yaml + + go_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Run unit test + run: go test + + checkhealth: + runs-on: ubuntu-latest + needs: go_test + steps: + - uses: actions/checkout@v4 + + - name: Run checkhealth + run: make checkhealth + + - id: pr_calculate + run: echo "pr=pr#${{ github.ref_name }}" | sed "s/\/merge//" >> "$GITHUB_OUTPUT" + + - id: sha_short + run: echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + + - uses: actions/upload-artifact@v4 + with: + name: daje-${{ steps.pr_calculate.outputs.pr }}-${{ steps.sha_short.outputs.sha_short }} + path: bin/daje + diff --git a/.gitignore b/.gitignore index ce27c3b..a53b64a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ bin # Mac .DS_Store dist/ + +# DAJE +testdata diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..db2f909 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,70 @@ +# Development documentation + +## Git Workflow + +We use the [**Forking Workflow**](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow), so first of all you need a fork of the project and only then you can start contribute to the project. + +## Branches + +The main branch is the only one that are going to be used, no development. The reason is that we don't need it at this moment, we will consider adding more complexity later on if necessary. + +## Requirements + +- [go](https://go.dev/) version **1.18^** +- [gmake](https://www.gnu.org/software/make/) + +## Setup environment + +``` +go mod tidy +``` + +## Run test with testdata + +In the root folder, run: + +``` +make build-test-dev +``` + +This generates all the binary files necessary for daje, now you should find `daje` inside the `bin` directory. To check if everything is gone ok you can run: + +``` +./bin/daje checkhealth +``` + +You should have something like this: + +```bash +----- Start CLEAN ----- + +# Remove all the daje metadata and builds... +rm -r /bin &>/dev/null + +----- End CLEAN ----- + +----- Start BUILD-TEST-DEV ----- + +# Building daje for development environment... +go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.ConfigBasepath=/testdata -X +github.com/Schrodinger-Hat/Daje/constants.Version=" -o ./bin/daje . + +----- End BUILD-TEST-DEV ----- + +----- Start CHECKHEALTH ----- + +# run checkhealth command... +./bin/daje checkhealth +Version: +Configuration path: /testdata/daje.conf +Tuning: true + +----- End CHECKHEALTH ----- +``` + +## Version + +Read this [https://go.dev/doc/modules/version-numbers](https://go.dev/doc/modules/version-numbers). + +Every pull request merged to main will create a new version, this mean that every commit to the main branch will create a new version. + diff --git a/Makefile b/Makefile index cdfab5f..24ae183 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,43 @@ -build: - @echo "Building daje..." - go build -o ./bin/daje . \ No newline at end of file +CURRENT_DIR := $(shell pwd) +BRANCH := $(shell git branch --show-current) +DAJE_TEST_NAME := daje-test-$(BRANCH) + +# Build Flags +FLAG_PREFIX := -X github.com/Schroedinger-Hat/Daje/constants +# TEST-DEV +FLAG_TEST-DEV_CONFIGBASEPATH := $(FLAG_PREFIX).ConfigBasepath=$(CURRENT_DIR)/testdata +FLAG_TEST-DEV_VERSION := $(FLAG_PREFIX).Version=$(BRANCH)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ') +# PROD +FLAG_VERSION := $(FLAG_PREFIX).Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD) + +clean: + @echo "\n----- Start CLEAN -----\n" + @echo "# Remove all the daje metadata and builds..." + rm -r $(CURRENT_DIR)/bin &2>/dev/null + @echo "\n----- End CLEAN -----" + +test: + @echo "\n----- Start BUILD -----\n" + @echo "# Running unit test..." + go test ./... + @echo "\n----- End BUILD -----" + +# The version in this build has the form `|` +build: test clean + @echo "\n----- Start BUILD -----\n" + @echo "# Building daje for production environment..." + go build -ldflags "$(FLAG_VERSION)" -o ./bin/daje . + @echo "\n----- End BUILD -----" + +# For debugging reason the version in this build has the form `++` +build-test-dev: test clean + @echo "\n----- Start BUILD-TEST-DEV -----\n" + @echo "# Building daje for development environment..." + go build -ldflags "$(FLAG_TEST-DEV_CONFIGBASEPATH) $(FLAG_TEST-DEV_VERSION)" -o ./bin/$(DAJE_TEST_NAME) . + @echo "\n----- End BUILD-TEST-DEV -----" + +checkhealth: build-test-dev + @echo "\n----- Start CHECKHEALTH -----\n" + @echo "# run checkhealth command..." + ./bin/$(DAJE_TEST_NAME) checkhealth + @echo "\n----- End CHECKHEALTH -----" diff --git a/README.md b/README.md index b8abc6c..a830daa 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,6 @@ A general purpose dotfiles installer under development, not ready to be used! -### Tech stack - -- [golang](https://go.dev/) - - - ## Usage WIP @@ -67,7 +61,8 @@ WIP Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. -If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +If you have a suggestion that would make this better, please fork the repo and create a pull request, you can find all the development information in [DEVELOPMENT.md](DEVELOPMENT.md). You can also simply open an issue with the tag "enhancement". + Don't forget to give the project a star! Thanks again! diff --git a/constants/constants_test.go b/constants/constants_test.go new file mode 100644 index 0000000..1255fc8 --- /dev/null +++ b/constants/constants_test.go @@ -0,0 +1 @@ +package constants diff --git a/constants/contants.go b/constants/contants.go index ac13532..17e3136 100644 --- a/constants/contants.go +++ b/constants/contants.go @@ -1,3 +1,19 @@ package constants -const DajeDotFile = ".daje" +var ConfigBasepath = "" +var ConfigFileName = ".dajerc" +var ConfigPathOrder = []string{ + ".config/daje/", + ".", +} + +var ConfigParameters = []string{ + "dotfiles.local", + "dotfiles.remote", +} + +var ConfigParametersPath = []string{ + "dotfiles.local", +} + +var Version = "" diff --git a/go.mod b/go.mod index d4fd62b..5bb2a07 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,31 @@ -module github.com/Schrodinger-Hat/Daje +module github.com/Schroedinger-Hat/Daje go 1.18 -require github.com/spf13/cobra v1.4.0 +require ( + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.19.0 +) require ( - github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0dd8697..4966411 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,69 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= -github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..70de080 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,73 @@ +package config + +import ( + "errors" + "log" + "os" + "path" + + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/spf13/viper" +) + +type configFunctionReturn struct { + Value string + Error error +} + +func LoadConfig() error { + configFilePath := "" + viperReadInConfig := func() configFunctionReturn { + viper.SetConfigFile(configFilePath) + return configFunctionReturn{"", viper.ReadInConfig()} + } + functionOrder := []func() configFunctionReturn{ + checkBasePath, + getConfigFilePath, + viperReadInConfig, + } + + for _, function := range functionOrder { + result := function() + if result.Value != "" { + configFilePath = result.Value + } + if result.Error != nil { + errorMessage := "LoadConfig->" + result.Error.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + } + + pathRelativeToAbsolute(path.Dir(configFilePath)) + return nil +} + +func checkBasePath() configFunctionReturn { + if constants.ConfigBasepath == "" { + homepath, err := os.UserHomeDir() + if err != nil { + return configFunctionReturn{"", errors.New("getConfigFilePath: User home not found")} + } + constants.ConfigBasepath = homepath + } + return configFunctionReturn{"", nil} +} + +func pathRelativeToAbsolute(configDirectory string) { + for _, value := range constants.ConfigParametersPath { + configValue := viper.GetString(value) + viper.Set(value, path.Join(configDirectory, configValue)) + } +} + +func getConfigFilePath() configFunctionReturn { + for _, value := range constants.ConfigPathOrder { + currentFilepath := path.Join(constants.ConfigBasepath, value, constants.ConfigFileName) + _, err := os.Stat(currentFilepath) + if err == nil { + return configFunctionReturn{currentFilepath, nil} + } + } + return configFunctionReturn{"", errors.New("getConfigFilePath: Configuration not found")} +} diff --git a/internal/config/config_folder.go b/internal/config/config_folder.go deleted file mode 100644 index 4e7f54a..0000000 --- a/internal/config/config_folder.go +++ /dev/null @@ -1,39 +0,0 @@ -package config - -import ( - "log" - "os" - "os/user" - "path/filepath" - - "github.com/Schrodinger-Hat/Daje/constants" -) - -func InitEmptyDaje() error { - currentUser, err := user.Current() - if err != nil { - return err - } - dotFile := filepath.Join(currentUser.HomeDir, constants.DajeDotFile) - if err = os.Mkdir(dotFile, os.ModeDir); err != nil { - return err - } - return nil -} - -func IsDajeInitialized() bool { - currentUser, err := user.Current() - if err != nil { - log.Fatal(err) - } - dotFile := filepath.Join(currentUser.HomeDir, constants.DajeDotFile) - if _, err := os.Stat(dotFile); err != nil { - if os.IsNotExist(err) { - return false - } - - log.Fatal(err) - } - - return true -} diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..1c3ab98 --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1,55 @@ +package config + +import ( + "errors" + "os" + "path" + "testing" + + "github.com/Schroedinger-Hat/Daje/constants" +) + +const configNotExistsFileName = ".confignotexists" + +func Test_getConfigFilePathShouldPassWithNoErrorsWhenFindConfigurationFile(t *testing.T) { + workingDirectory, _ := os.Getwd() + constants.ConfigBasepath = workingDirectory + "/../../testdata" + + result := getConfigFilePath() + + if result.Error != nil { + t.Fatalf("getConfigFilePath should pass with no errors when find configuration file: expected=\"\" - get=\"%v\"", result.Error) + } +} + +func Test_getConfigFilePathShouldReturnTheExactPathWhenItFindTheConfigurationFile(t *testing.T) { + workingDirectory, _ := os.Getwd() + constants.ConfigBasepath = workingDirectory + "/../../testdata" + expectedConfigPath := path.Join(constants.ConfigBasepath, "../testdata/.config/daje", constants.ConfigFileName) + + result := getConfigFilePath() + + if result.Value != expectedConfigPath { + t.Fatalf("getConfigFilePath should return the exact path when find configuration file: expected=%v - get=%v", expectedConfigPath, result.Value) + } +} + +func Test_getConfigFilePathShouldFailWhenDontFindConfigurationFile(t *testing.T) { + constants.ConfigFileName = configNotExistsFileName + + result := getConfigFilePath() + errExpected := errors.New("getConfigFilePath: Configuration not found") + + if result.Error.Error() != errExpected.Error() { + t.Fatalf("getConfigFilePath should fail when don't find configuration file: expected=%v - get=%v", errExpected, result.Error) + } +} + +func Test_getConfigFilePathShouldHaveEmptyPathWhenDontFindConfigurationFile(t *testing.T) { + constants.ConfigFileName = configNotExistsFileName + result := getConfigFilePath() + + if result.Value != "" { + t.Fatalf("getConfigFilePath should have empty path when don't find configuration file: expected=\"\" - get=%v", result.Value) + } +} diff --git a/internal/dotfiles/init.go b/internal/dotfiles/init.go new file mode 100644 index 0000000..0a7fb89 --- /dev/null +++ b/internal/dotfiles/init.go @@ -0,0 +1,22 @@ +package dotfiles + +import ( + "errors" + "log" + "os" + "path" + + "github.com/spf13/viper" +) + +func InitializeDotfiles() error { + err := os.MkdirAll(path.Join(viper.GetString("dotfiles.local")), os.ModePerm) + if err != nil { + errorMessage := "InitializeDotfiles->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + + // TODO: clone dotfiles.remote + return nil +} diff --git a/internal/dotfiles/init_test.go b/internal/dotfiles/init_test.go new file mode 100644 index 0000000..3acdce0 --- /dev/null +++ b/internal/dotfiles/init_test.go @@ -0,0 +1 @@ +package dotfiles diff --git a/main.go b/main.go index 254ea12..154b026 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,13 @@ package main import ( + "log" "os" - "github.com/Schrodinger-Hat/Daje/pkg/cmd/root" + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/Schroedinger-Hat/Daje/internal/config" + "github.com/Schroedinger-Hat/Daje/pkg/cmd/root" + "github.com/spf13/viper" ) type exitCode int @@ -14,6 +18,13 @@ const ( ) func main() { + viper.SetConfigType("yaml") + viper.SetConfigName(constants.ConfigFileName) + err := config.LoadConfig() + if err != nil { + errorMessage := "main->" + err.Error() + log.Fatal(errorMessage) + } code := mainRun() os.Exit(int(code)) } diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..1141a43 --- /dev/null +++ b/main_test.go @@ -0,0 +1,24 @@ +package main + +import ( + "os" + "testing" +) + +// For fun +func Test_MainRunShouldExitOkWhenNoSubcommand(t *testing.T) { + _, w, _ := os.Pipe() + stdout := os.Stdout + stderr := os.Stderr + + os.Stdout = w + os.Stderr = w + + if mainRun() != exitOk { + t.Fatal("mainRun() not ok") + } + + _ = w.Close() + os.Stdout = stdout + os.Stderr = stderr +} diff --git a/old/install.yml b/old/install.yml deleted file mode 100644 index cc18855..0000000 --- a/old/install.yml +++ /dev/null @@ -1,145 +0,0 @@ ---- -- hosts: localhost - become: true - tasks: - - name: Get Profile variables - include_vars: "profiles/{{ profile }}.yml" - when: profile is defined - - - name: Get Os variables if no profile - include_vars: "os_{{ ansible_facts['distribution'] }}.yml" - when: profile is undefined - - - name: Before installation - block: - - name: Print before tasks - debug: - var: before - - - name: Run before tasks - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ before }}" - when: before is defined - - - name: Create Workspaces directory - file: - path: "{{ home_dir }}/{{ workspace_dir }}" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - when: workspace_dir is defined - - - name: Update packages - shell: "{{ update_command }}" - when: update_command is defined - become_user: "{{ username }}" - - - name: Install IDE - block: - - name: Print ide packages - debug: - var: ide_packages - - - name: Install IDE packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ ide_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init IDE configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ ide_config }}" - - - name: Copy user local directory - copy: - src: .local/ - dest: "{{ home_dir }}/.local" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - remote_src: yes - mode: "0755" - - - name: Copy environment configuration - copy: - src: .env - dest: "{{ home_dir }}/.env" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - mode: "0755" - - - name: Copy aliases - copy: - src: .aliases - dest: "{{ home_dir }}/.aliases" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - mode: "0755" - - - name: Set default shell - shell: "sudo usermod --shell /bin/{{ default_shell }} {{ username }}" - ignore_errors: true - - - name: Set default keyboard layout using setxkbmap - shell: "setxkbmap -layout {{ default_keyboard }}" - when: default_keyboard is defined - become_user: "{{ username }}" - when: ide_install - - - name: Install system environment - block: - - name: Print system packages - debug: - var: system_packages - - - name: Install system packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ system_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init system configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ system_config }}" - when: system_config is defined - when: system_install - - - name: Install general packages - block: - - name: Print system packages - debug: - var: general_packages - - - name: Install general packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ general_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init general configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ general_config }}" - when: general_config is defined - when: general_install - - - name: After installation - block: - - name: Print after tasks - debug: - var: after - - - name: Run after tasks - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ after }}" - when: after is defined diff --git a/old/tasks/alacritty.yml b/old/tasks/alacritty.yml deleted file mode 100644 index be71f7d..0000000 --- a/old/tasks/alacritty.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Create alacritty configuration directory - file: - path: "{{ home_dir }}/.config/alacritty" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Init alacritty configuration - copy: - remote_src: yes - src: .config/alacritty/alacritty.yml - dest: "{{ home_dir }}/.config/alacritty/alacritty.yml" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes diff --git a/old/tasks/bash.yml b/old/tasks/bash.yml deleted file mode 100644 index be48ff5..0000000 --- a/old/tasks/bash.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Init bashrc - copy: - remote_src: yes - src: .bashrc - dest: "{{ home_dir }}/.bashrc" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Install bash configuration dependencies - shell: "{{ install_command }} {{ bash_package }}" - loop: - - bash-completion - loop_control: - loop_var: bash_package - become_user: "{{ username }}" - diff --git a/old/tasks/bluetooth.yml b/old/tasks/bluetooth.yml deleted file mode 100644 index 1d0d2d3..0000000 --- a/old/tasks/bluetooth.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Enable and start bluetooth - systemd: - name: bluetooth - state: started - enabled: yes - diff --git a/old/tasks/dunst.yml b/old/tasks/dunst.yml deleted file mode 100644 index e5841a5..0000000 --- a/old/tasks/dunst.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy Dunst configurations - copy: - src: .config/dunst/ - dest: "{{ home_dir }}/.config/dunst/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/git.yml b/old/tasks/git.yml deleted file mode 100644 index 5467a6a..0000000 --- a/old/tasks/git.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Add Global gitignore - copy: - remote_src: yes - src: .gitignore - dest: "{{ home_dir }}/.gitignore" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Add Global gitconfig - copy: - remote_src: yes - src: .gitconfig - dest: "{{ home_dir }}/.gitconfig" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/grub2-themes.yml b/old/tasks/grub2-themes.yml deleted file mode 100644 index 58ca469..0000000 --- a/old/tasks/grub2-themes.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Remove grub2-themes repository if already exists - file: - state: absent - path: "/tmp/grub2-themes/" - -- name: Clone grub2-themes repository - git: - repo: git@github.com:vinceliuice/grub2-themes.git - dest: "/tmp/grub2-themes/" - become_user: "{{ username }}" - -- name: Install grub2 whitesur theme - shell: - cmd: "./install.sh -b -t whitesur -i color" - chdir: "/tmp/grub2-themes" - become: true - ignore_errors: true - diff --git a/old/tasks/gtk3.yml b/old/tasks/gtk3.yml deleted file mode 100644 index fc18d18..0000000 --- a/old/tasks/gtk3.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Copy gtk3 session - copy: - src: .config/gtk-3.0/ - dest: "{{ home_dir }}/.config/gtk-3.0/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - remote_src: yes diff --git a/old/tasks/homebrew.yml b/old/tasks/homebrew.yml deleted file mode 100644 index c202294..0000000 --- a/old/tasks/homebrew.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -- name: Enable xcode-select - shell: "xcode-select --install" - register: xcode_result - ignore_errors: true - become_user: "{{ username }}" - -- name: Check if xcode is already installed - debug: - msg: "Xcode is already installed" - when: xcode_result.rc != 0 - -- name: Install homebrew - block: - - name: Remove homebrew repository if already exists - file: - state: absent - path: "/tmp/homebrew.sh" - - - name: Download homebrew installation - get_url: - url: https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh - dest: "/tmp/homebrew.sh" - - - name: Recursively change ownership of homebrew script - file: - path: "/tmp/homebrew.sh" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0777' - - - name: Run homebrew install script - shell: "NONINTERACTIVE=1 bash /tmp/homebrew.sh" - register: homebrew_result - ignore_errors: true - become_user: "{{ username }}" - diff --git a/old/tasks/i3.yml b/old/tasks/i3.yml deleted file mode 100644 index 988173a..0000000 --- a/old/tasks/i3.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Copy i3wm configurations - copy: - src: .config/i3/ - dest: "{{ home_dir }}/.config/i3/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - -- name: Restart i3 - shell: "i3-msg restart" - become_user: "{{ username }}" - diff --git a/old/tasks/neofetch.yml b/old/tasks/neofetch.yml deleted file mode 100644 index 830d535..0000000 --- a/old/tasks/neofetch.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy neofetch configurations - copy: - src: .config/neofetch/ - dest: "{{ home_dir }}/.config/neofetch/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/neovim.yml b/old/tasks/neovim.yml deleted file mode 100644 index cf21725..0000000 --- a/old/tasks/neovim.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Create config/nvim directory - file: - path: "{{ home_dir }}/.config/nvim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - -- name: copy init.vim - copy: - remote_src: yes - src: .config/nvim/init.vim - dest: "{{ home_dir }}/.config/nvim/init.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/nitrogen.yml b/old/tasks/nitrogen.yml deleted file mode 100644 index 3c35a04..0000000 --- a/old/tasks/nitrogen.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Copy nitrogen configuration - copy: - src: .config/nitrogen - dest: "{{ home_dir }}/.config/nitrogen" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes diff --git a/old/tasks/ohmyzsh.yml b/old/tasks/ohmyzsh.yml deleted file mode 100644 index a418bf8..0000000 --- a/old/tasks/ohmyzsh.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: Download oh-my-zsh installation - get_url: - url: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh - dest: "/tmp/ohmyzsh.sh" - -- name: Set default shell value if not defined - set_fact: - default_shell: "{{ default_shell | default('') }}" - when: default_shell is undefined - -- name: Run oh-my-zsh install script - shell: "KEEP_ZSHRC=yes CHSH={{ (default_shell == 'zsh' ) | ternary ('yes', 'no') }} sh /tmp/ohmyzsh.sh --unattended" - register: ohmyzsh_result - ignore_errors: true - become_user: "{{ username }}" - -- name: Check if oh-my-zsh is already installed - debug: - msg: "Oh-my-zsh is already installed" - when: ohmyzsh_result.stdout == "The $ZSH folder already exists ({{ home_dir }}/.oh-my-zsh).\nYou'll need to remove it if you want to reinstall." - diff --git a/old/tasks/paru.yml b/old/tasks/paru.yml deleted file mode 100644 index de9fb99..0000000 --- a/old/tasks/paru.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- name: Install base-devel packages - shell: sudo pacman -S --needed base-devel - -- name: Remove paru repository if already exists - file: - state: absent - path: "/tmp/paru" - -- name: Clone paru repository - git: - repo: https://github.com/Morganamilo/paru - dest: "/tmp/paru" - -- name: Recursively change ownership of paru directory - file: - path: "/tmp/paru" - state: directory - recurse: yes - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - -- name: Build paru - shell: - cmd: "makepkg -si" - chdir: "/tmp/paru" - become_user: "{{ username }}" - register: paru_result - ignore_errors: true - -- name: Check if paru is already install - debug: - msg: "Paru is probably already installed" - when: paru_result.rc != 0 - diff --git a/old/tasks/polybar.yml b/old/tasks/polybar.yml deleted file mode 100644 index 9f96430..0000000 --- a/old/tasks/polybar.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy polybar configurations - copy: - src: .config/polybar/ - dest: "{{ home_dir }}/.config/polybar/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/rofi.yml b/old/tasks/rofi.yml deleted file mode 100644 index 10b6512..0000000 --- a/old/tasks/rofi.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy rofi configurations - copy: - src: .config/rofi/ - dest: "{{ home_dir }}/.config/rofi/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/rofithemes.yml b/old/tasks/rofithemes.yml deleted file mode 100644 index 839d422..0000000 --- a/old/tasks/rofithemes.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Install rofi themes - git: - repo: https://github.com/lr-tech/rofi-themes-collection.git - dest: "/tmp/rofi-themes/" - -- name: Install rofi themes collection - copy: - src: /tmp/rofi-themes/themes - dest: "{{ home_dir }}/.local/share/rofi/" - directory_mode: yes - remote_src: yes - -- name: Recursively change ownership of a directory - file: - path: "{{ home_dir }}/.local/share/rofi/" - state: directory - recurse: yes - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' diff --git a/old/tasks/sddm-sugar-candy.yml b/old/tasks/sddm-sugar-candy.yml deleted file mode 100644 index ea0e01d..0000000 --- a/old/tasks/sddm-sugar-candy.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Install sddm themes and dependencies - shell: "{{ install_command }} {{ sddm_package }}" - loop: - - sddm-theme-sugar-candy-git - loop_control: - loop_var: sddm_package - become_user: "{{ username }}" - -- name: Update theme of sddm - replace: - path: /etc/sddm.conf - regexp: '^Current=$' - replace: 'Current=Sugar-Candy' - -- name: Update sddm sugar-candy theme - copy: - remote_src: yes - src: sddm/theme.conf - dest: "/usr/share/sddm/themes/Sugar-Candy/theme.conf" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - diff --git a/old/tasks/sddm.yml b/old/tasks/sddm.yml deleted file mode 100644 index 51b9a8e..0000000 --- a/old/tasks/sddm.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Copy sddm configurations - copy: - src: /usr/lib/sddm/sddm.conf.d/default.conf - dest: /etc/sddm.conf - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - -- name: Disable display-manager to change it - systemd: - name: display-manager - enabled: no - -- name: Enable sddm as diplay-manager - systemd: - name: sddm - enabled: yes - diff --git a/old/tasks/spotify.yml b/old/tasks/spotify.yml deleted file mode 100644 index 233bc27..0000000 --- a/old/tasks/spotify.yml +++ /dev/null @@ -1,63 +0,0 @@ ---- -- name: Install spotify configuration dependencies - shell: "{{ install_command }} {{ spotify_package }}" - loop: - - spicetify-cli - - spicetify-themes-git - loop_control: - loop_var: spotify_package - become_user: "{{ username }}" - -- name: Change permission to Spotify files - shell: > - chmod a+wr /opt/spotify ; - chmod a+wr /opt/spotify/Apps -R ; - -- name: Exec spotify to setup configuration - shell: > - spotify & - sleep 5 ; killall -q spotify - become_user: "{{ username }}" - -- name: Init spicetify configuration - shell: "spicetify" - become_user: "{{ username }}" - -- name: Enable spotify devtool - shell: "spicetify backup apply enable-devtool ;" - become_user: "{{ username }}" - -- name: Get spicetify directory for Dribbblish - shell: "echo $(dirname $(spicetify -c))/Themes/Dribbblish" - register: spicetify_dir - -- name: Create extensions directory - file: - path: "{{ spicetify_dir.stdout }}/../../Extensions" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Enable spotify devtool - copy: - src: /usr/share/spicetify-cli/Themes/Dribbblish/dribbblish.js - dest: "{{ spicetify_dir.stdout }}/../../Extensions/dribbblish.js" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - -- name: Enable dribbblish extension - shell: "spicetify config extensions {{ spicetify_dir.stdout }}/../../Extensions/dribbblish.js" - become_user: "{{ username }}" - -- name: Change theme and colorscheme - shell: "spicetify config current_theme Dribbblish color_scheme nord-dark" - become_user: "{{ username }}" - -- name: Change css configuration - shell: "spicetify config inject_css 1 replace_colors 1 overwrite_assets 1" - become_user: "{{ username }}" - -- name: Apply spicetify configuration - shell: "spicetify apply" - become_user: "{{ username }}" diff --git a/old/tasks/starship.yml b/old/tasks/starship.yml deleted file mode 100644 index c24945a..0000000 --- a/old/tasks/starship.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Download bash starship installation - get_url: - url: https://starship.rs/install.sh - dest: "/tmp/starship.sh" - -- name: Run starship install script - shell: "sh /tmp/starship.sh -y" - register: starship_result - ignore_errors: true - become_user: "{{ username }}" - diff --git a/old/tasks/tmux.yml b/old/tasks/tmux.yml deleted file mode 100644 index d956ba8..0000000 --- a/old/tasks/tmux.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init Tmux Conf - copy: - remote_src: yes - src: .tmux.conf - dest: "{{ home_dir }}/.tmux.conf" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/tpm.yml b/old/tasks/tpm.yml deleted file mode 100644 index 30f5877..0000000 --- a/old/tasks/tpm.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- name: Create Workspaces directory - file: - path: "{{ home_dir }}/.tmux/plugins" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - -- name: Install tmux plugin manager - git: - repo: https://github.com/tmux-plugins/tpm - dest: "{{ home_dir }}/.tmux/plugins/tpm" - -- name: Install Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}/.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/install_plugins" - -- name: Update Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}/.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/update_plugins all" - -- name: Clean Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/clean_plugins" - diff --git a/old/tasks/vim-plug.yml b/old/tasks/vim-plug.yml deleted file mode 100644 index eb31c42..0000000 --- a/old/tasks/vim-plug.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -- name: Create vim directory - file: - path: "{{ home_dir }}/.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Add vim plugins - copy: - remote_src: yes - src: .vim/plugins.vim - dest: "{{ home_dir }}/.vim/plugins.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Create vim autoload directory - file: - path: "{{ home_dir }}/.vim/autoload/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Download plug.vim - get_url: - url: https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - dest: "{{ home_dir }}/.vim/autoload/plug.vim" - -- name: Install vim plugins - shell: "vim +PlugInstall! +qa!" - args: - stdin: "\n" - become_user: "{{ username }}" - -- name: Clean vim plugins - shell: "vim +PlugClean! +qa!" - args: - stdin: "\n" - become_user: "{{ username }}" diff --git a/old/tasks/vim.yml b/old/tasks/vim.yml deleted file mode 100644 index c7cec86..0000000 --- a/old/tasks/vim.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init vimrc - copy: - remote_src: yes - src: .vimrc - dest: "{{ home_dir }}/.vimrc" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/zsh.yml b/old/tasks/zsh.yml deleted file mode 100644 index 47594d8..0000000 --- a/old/tasks/zsh.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init zshrc - copy: - remote_src: yes - src: .zshrc - dest: "{{ home_dir }}/.zshrc" - mode: '0755' - owner: "{{ username }}" - group: "{{ group | default(username) }}" - backup: yes - diff --git a/old/vars/os_Archlinux.yml b/old/vars/os_Archlinux.yml deleted file mode 100644 index bf49de6..0000000 --- a/old/vars/os_Archlinux.yml +++ /dev/null @@ -1,106 +0,0 @@ ---- -# === Archlinux === -os: Archlinux - -# === System configuration === -username: wabri -install_command: paru -S --noconfirm -update_command: paru -Syyu --noconfirm -home_dir: /home/wabri -workspace_dir: Documents/Workspaces -default_shell: zsh -default_keyboard: us -ide_install: true -system_install: true -general_install: true - -# === Before === -before: - - paru - -# === After === -after: - - bluetooth - -# === Packages === -ide_packages: - - git - - alacritty - - bash - - zsh - - vim - - tmux - - fzf - - nerd-fonts-source-code-pro - - ttf-iosevka-nerd - - ripgrep - - exa - - bat - - git-delta - - nodejs - -system_packages: - - i3-gaps - - playerctl - - arandr - - picom - - nitrogen - - dunst - - arc-x-icons-theme - - blueberry - - rofi - - nordic-theme - - breeze-icons - - graphite-cursor-theme-git - - betterlockscreen - - polybar - - nautilus - - pavucontrol - - sddm - -general_packages: - - vagrant - - spotify - - firefox - - obinskit - - htop - - gtop - - ncdu - - duf - - tldr - - etcher-bin - - vlc - - telegram-desktop - - whatsapp-for-linux - - slack-desktop - - bitwarden - - obs-studio - -# === Configurations === -ide_config: - - alacritty - - vim - - vim-plug - - tmux - - tpm - - bash - - ohmyzsh - - starship - - zsh - - ohmyzsh - - git - -system_config: - - dunst - - rofi - - rofithemes - - gtk3 - - nitrogen - - polybar - - i3 - - sddm - - sddm-sugar-candy - -general_config: - - spotify - diff --git a/old/vars/os_MacOSX.yml b/old/vars/os_MacOSX.yml deleted file mode 100644 index c643560..0000000 --- a/old/vars/os_MacOSX.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -# === System configuration === -username: test -group: staff -install_command: brew install --quiet -home_dir: /Users/test -workspace_dir: Documents/Workspaces -default_shell: zsh -ide_install: true -system_install: true -general_install: true - -# === Before === -before: - - homebrew - -# === Packages === -ide_packages: - - git - - alacritty - - zsh - - vim - - tmux - - fzf - - ripgrep - - exa - - bat - - git-delta - - starship - -system_packages: - - vagrant - - ruby - - tldr - - ncdu - - duf - - gtop - -general_packages: - - homebrew/cask-drivers/obinskit - - spotify - - balenaetcher - -# === Configurations === -ide_config: - - alacritty - - vim - - tmux - - zsh - - git - diff --git a/old/vars/profiles/profile1.yml b/old/vars/profiles/profile1.yml deleted file mode 100644 index 9b4e027..0000000 --- a/old/vars/profiles/profile1.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -# === Archlinux === -os: Debian - -# === System configuration === -username: test -install_command: apt-get install --yes -update_command: apt-get update --yes -home_dir: /home/test -workspace_dir: workspace -default_shell: bash -default_keyboard: us -ide_install: false -system_install: false -general_install: false - -# === Before === -#before: -# - paru - -# === After === -#after: -# - bluetooth - -# === Packages === -ide_packages: - - git - - bash - - vim - - tmux - -#system_packages: -# - playerctl -# - arandr -# - blueberry -# - rofi -# - nautilus - -#general_packages: -# - spotify -# - firefox -# - etcher-bin - -# === Configurations === - -ide_config: - - git - - vim - - bash - - tmux - -#system_config: -# - dunst -# - rofi - -#general_config: -# - spotify diff --git a/pkg/cmd/checkhealth/checkhealth.go b/pkg/cmd/checkhealth/checkhealth.go new file mode 100644 index 0000000..84276c2 --- /dev/null +++ b/pkg/cmd/checkhealth/checkhealth.go @@ -0,0 +1,32 @@ +package checkhealth + +import ( + "log" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/Schroedinger-Hat/Daje/constants" +) + +func CmdCheckhealth() *cobra.Command { + cmd := &cobra.Command{ + Use: "checkhealth [flags]", + Short: "Check Daje health", + RunE: func(cmd *cobra.Command, args []string) error { //nolint:all + return submitCmdCheckhealth() + }, + } + + return cmd +} + +func submitCmdCheckhealth() error { + log.Println("[Checkhealth]:[LoadConfig]", "Configuration Path:"+viper.GetViper().ConfigFileUsed()) + + for _, value := range constants.ConfigParameters { + log.Println("[Checkhealth]:[LoadConfig]", value+": "+viper.GetString(value)) + } + + return nil +} diff --git a/pkg/cmd/checkhealth/checkhealth_test.go b/pkg/cmd/checkhealth/checkhealth_test.go new file mode 100644 index 0000000..e02b12d --- /dev/null +++ b/pkg/cmd/checkhealth/checkhealth_test.go @@ -0,0 +1 @@ +package checkhealth diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 6d7cff2..0e7048a 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -1,37 +1,42 @@ package init import ( - "fmt" + "errors" + "log" "github.com/spf13/cobra" - "github.com/Schrodinger-Hat/Daje/internal/config" + "github.com/Schroedinger-Hat/Daje/internal/config" + "github.com/Schroedinger-Hat/Daje/internal/dotfiles" ) -func NewCmdInit() *cobra.Command { +func CmdInit() *cobra.Command { cmd := &cobra.Command{ Use: "init [flags]", Short: "Initialize daje on your system", RunE: func(cmd *cobra.Command, args []string) error { //nolint:all - return submitAction() + return submitCmdInit() }, } return cmd } -func submitAction() error { - if config.IsDajeInitialized() { - fmt.Println("Daje has been already initialized in the system.") - return nil +func submitCmdInit() error { + funcErrorHandle := func(err error) error { + errorMessage := "CmdInit->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) } - - err := config.InitEmptyDaje() - if err != nil { - return nil + functionOrder := []func() error{ + config.LoadConfig, + dotfiles.InitializeDotfiles, } - fmt.Println("Daje has been initialized successfully!") - + for _, function := range functionOrder { + if err := function(); err != nil { + return funcErrorHandle(err) + } + } return nil } diff --git a/pkg/cmd/init/init_test.go b/pkg/cmd/init/init_test.go new file mode 100644 index 0000000..3631b0c --- /dev/null +++ b/pkg/cmd/init/init_test.go @@ -0,0 +1 @@ +package init diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index f3b35f9..1599880 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -3,7 +3,8 @@ package root import ( "github.com/spf13/cobra" - initCmd "github.com/Schrodinger-Hat/Daje/pkg/cmd/init" + "github.com/Schroedinger-Hat/Daje/pkg/cmd/checkhealth" + initCmd "github.com/Schroedinger-Hat/Daje/pkg/cmd/init" ) func NewCmdRoot() *cobra.Command { @@ -17,7 +18,8 @@ $ daje init `, } - cmd.AddCommand(initCmd.NewCmdInit()) + cmd.AddCommand(initCmd.CmdInit()) + cmd.AddCommand(checkhealth.CmdCheckhealth()) return cmd } diff --git a/pkg/cmd/root/root_test.go b/pkg/cmd/root/root_test.go new file mode 100644 index 0000000..c804031 --- /dev/null +++ b/pkg/cmd/root/root_test.go @@ -0,0 +1 @@ +package root diff --git a/testdata/.config/daje/.dajerc b/testdata/.config/daje/.dajerc new file mode 100644 index 0000000..a57f439 --- /dev/null +++ b/testdata/.config/daje/.dajerc @@ -0,0 +1,3 @@ +dotfiles: + local: ../dotfiles + remote: https://github.com/Wabri/dotfiles diff --git a/testdata/.dajerc b/testdata/.dajerc new file mode 100644 index 0000000..2e0eb92 --- /dev/null +++ b/testdata/.dajerc @@ -0,0 +1,3 @@ +dotfiles: + local: .config/dotfiles + remote: https://github.com/Wabri/dotfiles