Skip to content

Commit aa9474b

Browse files
committed
Implement new keyring template processor.
1 parent 7eb1425 commit aa9474b

File tree

10 files changed

+639
-278
lines changed

10 files changed

+639
-278
lines changed

.golangci.yaml

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
# More info on config here: https://github.com/golangci/golangci-lint#config-file
2-
run:
3-
deadline: 10s
4-
issues-exit-code: 1
5-
tests: true
6-
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
version: "2"
73
output:
84
formats:
9-
- format: colored-line-number
10-
print-issued-lines: true
11-
print-linter-name: true
12-
13-
linters-settings:
14-
govet:
15-
shadow: true
16-
golint:
17-
min-confidence: 0
18-
dupl:
19-
threshold: 100
20-
goconst:
21-
min-len: 2
22-
min-occurrences: 2
23-
5+
text:
6+
path: stdout
7+
print-linter-name: true
8+
print-issued-lines: true
249
linters:
25-
disable-all: true
10+
default: none
2611
enable:
27-
- revive
28-
- govet
29-
- errcheck
30-
- unused
31-
- ineffassign
32-
- typecheck
3312
- dupl
13+
- errcheck
3414
- goconst
3515
- gosec
36-
- goimports
37-
- gosimple
16+
- govet
17+
- ineffassign
18+
- revive
3819
- staticcheck
3920
- unused
40-
41-
issues:
42-
exclude-use-default: false
43-
exclude-dirs:
44-
- bin
45-
- vendor
46-
- var
47-
- tmp
48-
exclude-files:
49-
- \.pb\.go$
50-
- \.pb\.goclay\.go$
51-
exclude:
52-
# # _ instead of err checks
53-
# - G104
54-
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
55-
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv|.*Rollback). is not checked
21+
settings:
22+
dupl:
23+
threshold: 100
24+
goconst:
25+
min-len: 2
26+
min-occurrences: 2
27+
exclusions:
28+
generated: lax
29+
rules:
30+
- path: (.+)\.go$
31+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv|.*Rollback). is not checked
32+
paths:
33+
- \.pb\.go$
34+
- \.pb\.goclay\.go$
35+
- bin
36+
- vendor
37+
- var
38+
- tmp
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- goimports
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- \.pb\.go$
49+
- \.pb\.goclay\.go$
50+
- bin
51+
- vendor
52+
- var
53+
- tmp
54+
- third_party$
55+
- builtin$
56+
- examples$

Makefile

Lines changed: 150 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,186 @@ LOCAL_BIN:=$(CURDIR)/bin
2323

2424
# Linter config.
2525
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
26-
GOLANGCI_TAG:=1.64.5
26+
GOLANGCI_TAG:=2.3.0
27+
28+
GOTESTFMT_BIN:=$(GOBIN)/gotestfmt
29+
30+
# Color definitions
31+
RED=\033[0;31m
32+
GREEN=\033[0;32m
33+
YELLOW=\033[0;33m
34+
BLUE=\033[0;34m
35+
MAGENTA=\033[0;35m
36+
CYAN=\033[0;36m
37+
WHITE=\033[0;37m
38+
BOLD=\033[1m
39+
RESET=\033[0m
40+
41+
# Disable colors on Windows.
42+
ifeq ($(OS),Windows_NT)
43+
RED=
44+
GREEN=
45+
YELLOW=
46+
BLUE=
47+
MAGENTA=
48+
CYAN=
49+
WHITE=
50+
BOLD=
51+
RESET=
52+
endif
53+
54+
# Print functions
55+
define print_header
56+
@echo "$(BOLD)$(CYAN)╔═════════════════════════════════════════════════════════════╗$(RESET)"
57+
@echo "$(BOLD)$(CYAN)║ LAUNCHR ║$(RESET)"
58+
@echo "$(BOLD)$(CYAN)╚═════════════════════════════════════════════════════════════╝$(RESET)"
59+
endef
60+
61+
define print_success
62+
@echo "$(BOLD)$(GREEN)$(1)$(RESET)"
63+
@echo
64+
endef
65+
66+
define print_info
67+
@echo "$(BOLD)$(BLUE)📋 $(1)$(RESET)"
68+
@echo
69+
endef
70+
71+
define print_warning
72+
@echo "$(BOLD)$(YELLOW)⚠️ $(1)$(RESET)"
73+
@echo
74+
endef
75+
76+
define print_error
77+
@echo "$(BOLD)$(RED)$(1)$(RESET)"
78+
@echo
79+
endef
80+
81+
define print_step
82+
@echo "$(BOLD)$(MAGENTA)🔧 $(1)$(RESET)"
83+
endef
2784

2885
.PHONY: all
29-
all: deps test build
86+
all: banner deps test-short build
87+
$(call print_success,"🎉 All tasks completed successfully!")
88+
89+
.PHONY: banner
90+
banner:
91+
$(call print_header)
92+
@echo "$(BOLD)$(WHITE)📦 Version: $(APP_VERSION)$(RESET)"
93+
@echo "$(BOLD)$(WHITE)🌿 Branch: $(GIT_BRANCH)$(RESET)"
94+
@echo "$(BOLD)$(WHITE)🔗 Hash: $(GIT_HASH)$(RESET)"
95+
@echo
3096

3197
# Install go dependencies
3298
.PHONY: deps
3399
deps:
34-
$(info Installing go dependencies...)
35-
go mod download
100+
$(call print_step,"Installing go dependencies...")
101+
@go mod download
102+
$(call print_success,"Dependencies installed successfully!")
36103

37104
# Run all tests
38105
.PHONY: test
39-
test:
40-
$(info Running tests...)
41-
go test ./...
106+
test: .install-gotestfmt
107+
$(call print_step,"Running all tests...")
108+
@go test -json -v ./... | $(GOTESTFMT_BIN) -hide all && \
109+
echo "$(BOLD)$(GREEN)🧪 ✅ All tests passed$(RESET)" || \
110+
echo "$(BOLD)$(RED)🧪 ❌ Some tests failed$(RESET)"
111+
@echo
112+
113+
# Run short tests
114+
.PHONY: test-short
115+
test-short: .install-gotestfmt
116+
$(call print_step,"Running short tests...")
117+
@go test -json -short -v ./... | $(GOTESTFMT_BIN) -hide all && \
118+
echo "$(BOLD)$(GREEN)🧪 ✅ All short tests passed$(RESET)" || \
119+
echo "$(BOLD)$(RED)🧪 ❌ Some short tests failed$(RESET)"
120+
@echo
42121

43122
# Build launchr
44123
.PHONY: build
45124
build:
46-
$(info Building launchr...)
125+
$(call print_step,"Building launchr...")
47126
# Application related information available on build time.
48127
$(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
49128
$(eval BIN?=$(LOCAL_BIN)/launchr)
50-
go generate ./...
51-
$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
129+
@go generate ./...
130+
@$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
131+
$(call print_success,"🔨 Build completed: $(BIN)")
52132

53133
# Install launchr
54134
.PHONY: install
55135
install: all
56-
install:
57-
$(info Installing launchr to GOPATH...)
58-
cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
136+
$(call print_step,"Installing launchr to GOPATH...")
137+
@cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
138+
$(call print_success,"🚀 launchr installed to $(GOBIN)/launchr")
59139

60140
# Install and run linters
61141
.PHONY: lint
62-
lint: .install-lint .lint
142+
lint: .install-lint .lint-fix
63143

64144
# Install golangci-lint binary
65145
.PHONY: .install-lint
66146
.install-lint:
67147
ifeq ($(wildcard $(GOLANGCI_BIN)),)
68-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
148+
$(call print_step,"Installing golangci-lint v$(GOLANGCI_TAG)...")
149+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
150+
$(call print_success,"golangci-lint installed!")
151+
endif
152+
153+
# Install gotestfmt binary
154+
.PHONY: .install-gotestfmt
155+
.install-gotestfmt:
156+
ifeq ($(wildcard $(GOTESTFMT_BIN)),)
157+
$(call print_step,"Installing gotestfmt...")
158+
@go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
159+
$(call print_success,"gotestfmt installed!")
69160
endif
70161

71162
# Runs linters
163+
.PHONY: .lint-fix
164+
.lint-fix:
165+
$(call print_step,"Running linters with auto-fix...")
166+
@$(GOLANGCI_BIN) run --fix ./... && \
167+
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
168+
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
169+
@echo
170+
72171
.PHONY: .lint
73172
.lint:
74-
$(info Running lint...)
75-
$(GOLANGCI_BIN) run --fix ./...
173+
$(call print_step,"Running linters...")
174+
@$(GOLANGCI_BIN) run && \
175+
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
176+
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
177+
@echo
178+
179+
# Clean build artifacts
180+
.PHONY: clean
181+
clean:
182+
$(call print_step,"Cleaning build artifacts...")
183+
@rm -rf $(LOCAL_BIN)
184+
$(call print_success,"🧹 Cleanup completed!")
185+
186+
# Show help
187+
.PHONY: help
188+
help:
189+
$(call print_header)
190+
@echo "$(BOLD)$(WHITE)Available targets:$(RESET)"
191+
@echo ""
192+
@echo " $(BOLD)$(GREEN)all$(RESET) 🎯 Run deps, test, and build"
193+
@echo " $(BOLD)$(GREEN)deps$(RESET) 📦 Install go dependencies"
194+
@echo " $(BOLD)$(GREEN)test$(RESET) 🧪 Run all tests"
195+
@echo " $(BOLD)$(GREEN)test-short$(RESET) ⚡ Run short tests only"
196+
@echo " $(BOLD)$(GREEN)build$(RESET) 🔨 Build launchr binary"
197+
@echo " $(BOLD)$(GREEN)install$(RESET) 🚀 Install launchr to GOPATH"
198+
@echo " $(BOLD)$(GREEN)lint$(RESET) 🔍 Run linters with auto-fix"
199+
@echo " $(BOLD)$(GREEN)clean$(RESET) 🧹 Clean build artifacts"
200+
@echo " $(BOLD)$(GREEN)help$(RESET) ❓ Show this help message"
201+
@echo ""
202+
@echo "$(BOLD)$(CYAN)Environment variables:$(RESET)"
203+
@echo " $(BOLD)$(YELLOW)DEBUG=1$(RESET) Enable debug build"
204+
@echo " $(BOLD)$(YELLOW)BIN=path$(RESET) Custom binary output path"
205+
@echo ""
206+
207+
# Default target shows help
208+
.DEFAULT_GOAL := help

askpass.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,39 @@ func (a AskPassWithTerminal) readPass(prompt string) (string, error) {
7979
return strings.TrimSpace(string(bytePassword)), nil
8080
}
8181

82-
// AskPassConstFlow implements AskPass and returns constant.
83-
type AskPassConstFlow string
82+
// AskPassConst implements AskPass and returns constant.
83+
type AskPassConst func() string
8484

8585
// GetPass implements AskPass interface.
86-
func (a AskPassConstFlow) GetPass() (string, error) { return string(a), nil }
86+
func (a AskPassConst) GetPass() (string, error) { return a(), nil }
8787

8888
// NewPass implements AskPass interface.
89-
func (a AskPassConstFlow) NewPass() (string, error) { return string(a), nil }
89+
func (a AskPassConst) NewPass() (string, error) { return a(), nil }
90+
91+
type AskPassFirstAvailable []AskPass
92+
93+
func (a AskPassFirstAvailable) GetPass() (string, error) {
94+
for _, a := range a {
95+
pass, err := a.GetPass()
96+
if err != nil {
97+
return "", err
98+
}
99+
if pass != "" {
100+
return pass, nil
101+
}
102+
}
103+
return "", nil
104+
}
105+
106+
func (a AskPassFirstAvailable) NewPass() (string, error) {
107+
for _, a := range a {
108+
pass, err := a.NewPass()
109+
if err != nil {
110+
return "", err
111+
}
112+
if pass != "" {
113+
return pass, nil
114+
}
115+
}
116+
return "", nil
117+
}

0 commit comments

Comments
 (0)