Skip to content

Commit

Permalink
Merge pull request #101 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.3.1
  • Loading branch information
andyone authored May 21, 2024
2 parents 57b8f1a + 0e86e22 commit b7b1836
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x' ]
go: [ '1.21.x', '1.22.x' ]

steps:
- name: Checkout
Expand Down
58 changes: 36 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
################################################################################

# This Makefile generated by GoMakeGen 2.3.2 using next command:
# This Makefile generated by GoMakeGen 3.0.1 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen

################################################################################

export GO111MODULE=on

ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

COMPAT ?= 1.18
COMPAT ?= 1.19
MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

Expand All @@ -27,13 +25,16 @@ GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)
all: scratch ## Build all binaries

scratch:
go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" scratch.go
@echo "Building scratch…"
@go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" scratch.go

install: ## Install all binaries
cp scratch /usr/bin/scratch
@echo "Installing binaries…"
@cp scratch /usr/bin/scratch

uninstall: ## Uninstall all binaries
rm -f /usr/bin/scratch
@echo "Removing installed binaries…"
@rm -f /usr/bin/scratch

init: mod-init ## Initialize new module

Expand All @@ -44,47 +45,60 @@ update: mod-update ## Update dependencies to the latest versions
vendor: mod-vendor ## Make vendored copy of dependencies

mod-init:
@echo "[1/2] Modules initialization…"
ifdef MODULE_PATH ## Module path for initialization (String)
go mod init $(MODULE_PATH)
@go mod init $(MODULE_PATH)
else
go mod init
@go mod init
endif

@echo "[2/2] Dependencies cleanup…"
ifdef COMPAT ## Compatible Go version (String)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
@go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
@go mod tidy $(VERBOSE_FLAG)
endif

mod-update:
@echo "[1/4] Updating dependencies…"
ifdef UPDATE_ALL ## Update all dependencies (Flag)
go get -u $(VERBOSE_FLAG) all
@go get -u $(VERBOSE_FLAG) all
else
go get -u $(VERBOSE_FLAG) ./...
@go get -u $(VERBOSE_FLAG) ./...
endif

@echo "[2/4] Stripping toolchain info…"
@grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || :

@echo "[3/4] Dependencies cleanup…"
ifdef COMPAT
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
@go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
@go mod tidy $(VERBOSE_FLAG)
endif

test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :
@echo "[4/4] Updating vendored dependencies…"
@test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

mod-download:
go mod download
@echo "Downloading dependencies…"
@go mod download

mod-vendor:
rm -rf vendor && go mod vendor $(VERBOSE_FLAG)
@echo "Vendoring dependencies…"
@rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
@echo "Formatting sources…"
@find . -name "*.go" -exec gofmt -s -w {} \;

vet: ## Runs 'go vet' over sources
go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...
@echo "Running 'go vet' over sources…"
@go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...

clean: ## Remove generated files
rm -f scratch
@echo "Removing built binaries…"
@rm -f scratch

help: ## Show this info
@echo -e '\n\033[1mTargets:\033[0m\n'
Expand All @@ -95,6 +109,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.3.2\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 3.0.1\033[0m\n'

################################################################################
28 changes: 19 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/system"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/terminal/input"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
Expand All @@ -38,7 +39,7 @@ import (

const (
APP = "scratch"
VER = "0.3.0"
VER = "0.3.1"
DESC = "Utility for generating blank files for apps and services"
)

Expand Down Expand Up @@ -80,11 +81,9 @@ func Run(gitRev string, gomod []byte) {

args, errs := options.Parse(optMap)

if len(errs) != 0 {
for _, err := range errs {
terminal.Error(err.Error())
}

if !errs.IsEmpty() {
terminal.Error("Options parsing errors:")
terminal.Error(errs.String())
os.Exit(1)
}

Expand Down Expand Up @@ -150,7 +149,7 @@ func configureUI() {
fmtc.DisableColors = true
}

terminal.Prompt = "› "
input.Prompt = "› "
}

// findTemplatesDir tries to find directory with templates
Expand Down Expand Up @@ -275,6 +274,7 @@ func listTemplateData(name string) {
}

fileSize := fsutil.GetSize(path.Join(t.Path, file))

fmtc.Printf(
" %s {s-}(%s){!}\n",
lscolors.ColorizePath(file),
Expand All @@ -283,6 +283,16 @@ func listTemplateData(name string) {
}

fmtc.NewLine()

for _, v := range knownVars.List {
_, ok := t.Vars[v]

if ok {
fmtc.Printf(" {s-}•{!} {s}%s — {&}%s{!}\n", v, knownVars.Info[v].Desc)
}
}

fmtc.NewLine()
}

// readVariablesValues reads values for variables from template
Expand All @@ -302,7 +312,7 @@ func readVariablesValues(vars Variables) error {

for {
fmtc.Printf("{s-}[%d/%d]{!} {c}%s:{!}\n", curVar, totalVar, knownVars.Info[v].Desc)
value, err := terminal.ReadUI("", true)
value, err := input.Read("", true)

fmtc.NewLine()

Expand Down Expand Up @@ -340,7 +350,7 @@ func printVariablesInfo(vars Variables) {

fmtc.NewLine()

ok, err := terminal.ReadAnswer("Everything is ok?", "y")
ok, err := input.ReadAnswer("Everything is ok?", "y")

fmtc.NewLine()

Expand Down
2 changes: 1 addition & 1 deletion app/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var knownVars = &VariableInfoStore{
Info: map[string]VariableInfo{
VAR_NAME: {"Name", `^[a-zA-Z0-9]+[a-zA-Z0-9\_\-\ ]{1,30}$`, false},
VAR_SHORT_NAME: {"Short name (binary name or repository name)", `^[a-z0-9\_\-]{2,32}$`, false},
VAR_VERSION: {"Version (in semver notation)", `^[0-9]+\.[0-9]*\.?[0-9]*$`, false},
VAR_VERSION: {"Version (in SemVer/EffVer notation)", `^[0-9]+\.[0-9]*\.?[0-9]*$`, false},
VAR_DESC: {"Description", `^.{16,128}$`, false},
VAR_DESC_README: {"Description for README file (part after 'app is… ')", `^.{16,128}$`, false},

Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module github.com/essentialkaos/scratch

go 1.18

require (
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.116.0
)
require github.com/essentialkaos/ek/v12 v12.125.0

require (
github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect
golang.org/x/sys v0.19.0 // indirect
github.com/essentialkaos/depsy v1.3.0 // indirect
github.com/essentialkaos/go-linenoise/v3 v3.6.0 // indirect
golang.org/x/sys v0.20.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.116.0 h1:lEe1pakqCFgbJMBQ+Ymrbd0GvzXdtg9/0nB6lgpuH6o=
github.com/essentialkaos/ek/v12 v12.116.0/go.mod h1:L3l8wkmXO9T72+hXc4nZosl7tj49XiU0gVrwiXyiYBg=
github.com/essentialkaos/go-linenoise/v3 v3.4.0 h1:g72w8x+/HIwOMBVvNaPYp+wMWVHrYZwzFAF7OfZR5Ts=
github.com/essentialkaos/go-linenoise/v3 v3.4.0/go.mod h1:t1kNLY2bSMQCy1JXOefD2BDLs/TTPMtTv3DFNV5uDSI=
github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU=
github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.125.0 h1:LVtDVESX0Rr0/34ZBOwgmpATaQfoQ/FDExqZyAzQp8I=
github.com/essentialkaos/ek/v12 v12.125.0/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y=
github.com/essentialkaos/go-linenoise/v3 v3.6.0 h1:deLcrodtLIkcHjNyW/MoQpjznXPVqvwlspxk7s/5YeY=
github.com/essentialkaos/go-linenoise/v3 v3.6.0/go.mod h1:Fi6kLdZdURkXHpRkIiX2nFGORNv81CXTZ2Mn72i/cn0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit b7b1836

Please sign in to comment.