diff --git a/.gitignore b/.gitignore
index d7888eaa..350c4412 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,7 @@
dist
# lets binary
-lets
+/lets
lets-dev
.lets
lets.my.yaml
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 75b9170d..116ea295 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -10,7 +10,7 @@ release:
builds:
- id: darwin-amd64
- main: .
+ main: ./cmd/lets
goos:
- darwin
goarch:
@@ -25,7 +25,7 @@ builds:
ldflags:
- -s -w -X main.version={{.Version}}
- id: darwin-arm64
- main: .
+ main: ./cmd/lets
goos:
- darwin
goarch:
@@ -38,9 +38,9 @@ builds:
flags:
- -mod=readonly
ldflags:
- - -s -w -X main.version={{.Version}}
+ - -s -w -X main.Version={{.Version}}
- id: linux-amd64
- main: .
+ main: ./cmd/lets
goos:
- linux
goarch:
diff --git a/.run/lets --version.run.xml b/.run/lets --version.run.xml
deleted file mode 100644
index 3e0230ab..00000000
--- a/.run/lets --version.run.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.run/lets print-env.run.xml b/.run/lets print-env.run.xml
deleted file mode 100644
index 5de089ce..00000000
--- a/.run/lets print-env.run.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.run/lets.run.xml b/.run/lets.run.xml
deleted file mode 100644
index 0b3c78d6..00000000
--- a/.run/lets.run.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 59df90af..83761e49 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -1,23 +1,23 @@
{
- // Use IntelliSense to learn about possible attributes.
- // Hover to view descriptions of existing attributes.
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "0.2.0",
- "configurations": [
- {
- "name": "Launch Package",
- "type": "go",
- "request": "launch",
- "mode": "auto",
- "program": "${fileDirname}"
- },
- {
- "name": "Run",
- "type": "go",
- "request": "launch",
- "mode": "auto",
- "program": "${workspaceRoot}",
- "args": []
- }
- ]
-}
\ No newline at end of file
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Launch Package",
+ "type": "go",
+ "request": "launch",
+ "mode": "auto",
+ "program": "${fileDirname}"
+ },
+ {
+ "name": "Run",
+ "type": "go",
+ "request": "launch",
+ "mode": "auto",
+ "program": "${workspaceRoot}/cmd/lets/main.go",
+ "args": []
+ }
+ ]
+}
diff --git a/main.go b/cmd/lets/main.go
similarity index 95%
rename from main.go
rename to cmd/lets/main.go
index 525429c2..7fa766eb 100644
--- a/main.go
+++ b/cmd/lets/main.go
@@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
)
-var version = "0.0.0-dev"
+var Version = "0.0.0-dev"
func main() {
ctx := getContext()
@@ -29,11 +29,11 @@ func main() {
logging.InitLogging(os.Stdout, os.Stderr)
- rootCmd := cmd.CreateRootCommand(version)
+ rootCmd := cmd.CreateRootCommand(Version)
rootCmd.InitDefaultHelpFlag()
rootCmd.InitDefaultVersionFlag()
reinitCompletionCmd := cmd.InitCompletionCmd(rootCmd, nil)
- cmd.InitSelfCmd(rootCmd, version)
+ cmd.InitSelfCmd(rootCmd, Version)
rootCmd.InitDefaultHelpCmd()
command, args, err := rootCmd.Traverse(os.Args[1:])
@@ -66,7 +66,7 @@ func main() {
rootFlags.config = os.Getenv("LETS_CONFIG")
}
- cfg, err := config.Load(rootFlags.config, configDir, version)
+ cfg, err := config.Load(rootFlags.config, configDir, Version)
if err != nil {
if failOnConfigError(rootCmd, command, rootFlags) {
log.Errorf("lets: config error: %s", err)
@@ -82,7 +82,7 @@ func main() {
if rootFlags.init {
wd, err := os.Getwd()
if err == nil {
- err = workdir.InitLetsFile(wd, version)
+ err = workdir.InitLetsFile(wd, Version)
}
if err != nil {
@@ -94,7 +94,7 @@ func main() {
}
if rootFlags.upgrade {
- upgrader, err := upgrade.NewBinaryUpgrader(registry.NewGithubRegistry(ctx), version)
+ upgrader, err := upgrade.NewBinaryUpgrader(registry.NewGithubRegistry(ctx), Version)
if err == nil {
err = upgrader.Upgrade()
}
diff --git a/docker-compose.yml b/docker-compose.yml
index 6e14c4a4..11691720 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -31,7 +31,7 @@ services:
- bash
- -c
- |
- go build -o /usr/bin/lets *.go
+ go build -o /usr/bin/lets cmd/lets/main.go
if [[ -n "${LETSOPT_TEST}" ]]; then
bats tests/"${LETSOPT_TEST}" ${LETSOPT_OPTS}
else
diff --git a/lets.build.yaml b/lets.build.yaml
index 52d24caa..69e402ec 100644
--- a/lets.build.yaml
+++ b/lets.build.yaml
@@ -9,3 +9,7 @@ commands:
build-lint-image:
description: Build lets lint docker image
cmd: docker build -t lets-lint -f Dockerfile --target linter .
+
+ goreleaser-dev:
+ description: Run goreleaser to test its build
+ cmd: goreleaser build --skip=validate --clean
diff --git a/lets.yaml b/lets.yaml
index 119b876a..52b00bb8 100644
--- a/lets.yaml
+++ b/lets.yaml
@@ -109,9 +109,9 @@ commands:
PATH2LETSDEV=$LETSOPT_PATH
fi
- go build -ldflags="-X main.version=${VERSION:1}-dev" -o "${BIN}" *.go && \
+ go build -ldflags="-X main.Version=${VERSION:1}-dev" -o "${BIN}" cmd/lets/main.go && \
sudo mv ./${BIN} $PATH2LETSDEV/${BIN} && \
- echo " - binary ${BIN} version ${VERSION} successfully installed in ${PATH2LETSDEV}"
+ echo " - binary ${BIN} version $($PATH2LETSDEV/${BIN} --version) successfully installed in ${PATH2LETSDEV}"
build:
description: Build lets from source code
@@ -120,9 +120,18 @@ commands:
cmd: |
VERSION=$(git describe)
BIN=${LETSOPT_BIN:-lets}
-
- go build -ldflags="-X main.version=${VERSION:1}-dev" -o ${BIN} *.go && \
- echo " - binary './${BIN}' (version ${VERSION}) successfully build"
+
+ go build \
+ -ldflags="-X main.Version=${VERSION:1}-dev" \
+ -o ${BIN} cmd/lets/main.go
+
+ success=$?
+ if [[ $success -eq 0 ]]; then
+ version=$(./${BIN} --version)
+ echo " - binary './${BIN}' ($version) successfully build"
+ else
+ echo "Failed to build"
+ fi
publish-docs:
work_dir: docs
diff --git a/tests/config_version.bats b/tests/config_version.bats
index 1311c13d..1b699148 100644
--- a/tests/config_version.bats
+++ b/tests/config_version.bats
@@ -3,33 +3,33 @@ load test_helpers
TEST_VERSION=0.0.2
setup() {
- load "${BATS_UTILS_PATH}/bats-support/load.bash"
- load "${BATS_UTILS_PATH}/bats-assert/load.bash"
- # NOTICE to test this functionality properly we building lets with specified version ${TEST_VERSION}
- go build -ldflags="-X main.version=${TEST_VERSION}" -o ./tests/config_version/lets *.go
- cd ./tests/config_version
+ load "${BATS_UTILS_PATH}/bats-support/load.bash"
+ load "${BATS_UTILS_PATH}/bats-assert/load.bash"
+ # NOTICE to test this functionality properly we building lets with specified version ${TEST_VERSION}
+ go build -ldflags="-X main.Version=${TEST_VERSION}" -o ./tests/config_version/lets cmd/lets/main.go
+ cd ./tests/config_version
}
teardown() {
- rm -f ./lets
+ rm -f ./lets
}
@test "config_version: if config version lower than lets version - its ok" {
- LETS_CONFIG=lets-with-version-0.0.1.yaml run ./lets
+ LETS_CONFIG=lets-with-version-0.0.1.yaml run ./lets
- assert_success
- assert_line --index 0 "A CLI task runner"
+ assert_success
+ assert_line --index 0 "A CLI task runner"
}
@test "config_version: if config version greater than lets version - fail - require upgrade" {
- LETS_CONFIG=lets-with-version-0.0.3.yaml run ./lets
+ LETS_CONFIG=lets-with-version-0.0.3.yaml run ./lets
- assert_failure
- assert_line --index 0 "lets: config error: config version '0.0.3' is not compatible with 'lets' version '0.0.2'. Please upgrade 'lets' to '0.0.3' using 'lets --upgrade' command or following documentation at https://lets-cli.org/docs/installation'"
+ assert_failure
+ assert_line --index 0 "lets: config error: config version '0.0.3' is not compatible with 'lets' version '0.0.2'. Please upgrade 'lets' to '0.0.3' using 'lets --upgrade' command or following documentation at https://lets-cli.org/docs/installation'"
}
@test "config_version: no version specified" {
- LETS_CONFIG=lets-without-version.yaml run ./lets
- assert_success
- assert_line --index 0 "A CLI task runner"
+ LETS_CONFIG=lets-without-version.yaml run ./lets
+ assert_success
+ assert_line --index 0 "A CLI task runner"
}