Skip to content

Commit

Permalink
Merge pull request #39 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.0.10
  • Loading branch information
andyone authored Mar 21, 2023
2 parents 99f9252 + 03c8dec commit b044c87
Show file tree
Hide file tree
Showing 53 changed files with 2,015 additions and 807 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:

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

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.0.0 using next command:
# This Makefile generated by GoMakeGen 2.2.0 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -13,6 +13,9 @@ ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

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

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

.DEFAULT_GOAL := help
Expand All @@ -23,7 +26,7 @@ endif
all: scratch ## Build all binaries

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

install: ## Install all binaries
cp scratch /usr/bin/scratch
Expand Down Expand Up @@ -65,13 +68,13 @@ else
go mod tidy $(VERBOSE_FLAG)
endif

test -d vendor && go mod vendor $(VERBOSE_FLAG) || :
test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

mod-download:
go mod download

mod-vendor:
go mod vendor $(VERBOSE_FLAG)
rm -rf vendor && go mod vendor $(VERBOSE_FLAG)

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
Expand All @@ -91,6 +94,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.0.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'

################################################################################
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#### From sources

To install the `scratch` from sources, make sure you have a working Go 1.17+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To install the `scratch` from sources, make sure you have a working Go 1.19+ workspace (_[instructions](https://golang.org/doc/install)_), then:

```
go install github.com/essentialkaos/scratch
Expand Down Expand Up @@ -66,11 +66,14 @@ Options
Examples
scratch package
List files in template "package"
scratch package .
Generate package blank files in current directory
Generate files based on tempalte "package" in current directory
scratch service $GOPATH/src/github.com/essentialkaos/myapp
Generate service blank files in sources directory
Generate files based on tempalte "service" in given directory
```

### Contributing
Expand Down
87 changes: 64 additions & 23 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -16,8 +16,11 @@ import (
"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/lscolors"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/path"
"github.com/essentialkaos/ek/v12/pluralize"
"github.com/essentialkaos/ek/v12/sortutil"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
Expand All @@ -31,7 +34,7 @@ import (

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

Expand All @@ -57,13 +60,12 @@ var optMap = options.Map{
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// useRawOutput is raw output flag (for cli command)
var useRawOutput = false

// ////////////////////////////////////////////////////////////////////////////////// //

// Init is main app func
func Init() {
preConfigureUI()

args, errs := options.Parse(optMap)

if len(errs) != 0 {
Expand All @@ -74,29 +76,25 @@ func Init() {
os.Exit(1)
}

preConfigureUI()
configureUI()

if options.Has(OPT_COMPLETION) {
switch {
case options.Has(OPT_COMPLETION):
os.Exit(genCompletion())
}

if options.Has(OPT_GENERATE_MAN) {
case options.Has(OPT_GENERATE_MAN):
os.Exit(genMan())
}

configureUI()

if options.GetB(OPT_VER) {
case options.GetB(OPT_VER):
os.Exit(showAbout())
}

if options.GetB(OPT_HELP) {
case options.GetB(OPT_HELP):
os.Exit(showUsage())
}

if len(args) < 2 {
switch len(args) {
case 0:
listTemplates()
} else {
case 1:
listTemplateData(args.Get(0).String())
default:
generateApp(
args.Get(0).String(),
args.Get(1).Clean().String(),
Expand All @@ -121,7 +119,6 @@ func preConfigureUI() {

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
useRawOutput = true
}

if os.Getenv("NO_COLOR") != "" {
Expand Down Expand Up @@ -206,6 +203,43 @@ func listTemplates() {
fmtc.NewLine()
}

// listTemplateData show list of files in template
func listTemplateData(name string) {
if !hasTemplate(name) {
printErrorAndExit("There is no templates with name \"%s\"", name)
}

t, err := getTemplate(name)

if err != nil {
printErrorAndExit(err.Error())
}

sortutil.StringsNatural(t.Data)

fmtc.Printf(
"\n {s-}┌{!} {*}%s{!} {s-}(%s){!}\n {s-}│{!}\n",
t.Name, pluralize.P("%d %s", len(t.Data), "file", "files"),
)

for i, file := range t.Data {
if i+1 != len(t.Data) {
fmtc.Printf(" {s-}├─{!}")
} else {
fmtc.Printf(" {s-}└─{!}")
}

fileSize := fsutil.GetSize(path.Join(t.Path, file))
fmtc.Printf(
" %s {s-}(%s){!}\n",
lscolors.ColorizePath(file),
fmtutil.PrettySize(fileSize),
)
}

fmtc.NewLine()
}

// readVariablesValues reads values for variables from template
func readVariablesValues(vars Variables) error {
var curVar, totalVar int
Expand Down Expand Up @@ -356,8 +390,15 @@ func genUsage() *usage.Info {
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")

info.AddExample("package .", "Generate package blank files in current directory")
info.AddExample("service $GOPATH/src/github.com/essentialkaos/myapp", "Generate service blank files in sources directory")
info.AddExample("package", "List files in template \"package\"")
info.AddExample(
"package .",
"Generate files based on tempalte \"package\" in current directory",
)
info.AddExample(
"service $GOPATH/src/github.com/essentialkaos/myapp",
"Generate files based on tempalte \"service\" in given directory",
)

return info
}
Expand Down
4 changes: 2 additions & 2 deletions app/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -68,7 +68,7 @@ type VariableInfo struct {
var knownVars = &VariableInfoStore{
// Info contains info about all supported variables
Info: map[string]VariableInfo{
VAR_NAME: {"Name", `^[a-zA-Z0-9\_\-]{2,32}$`, false},
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_DESC: {"Description", `^.{16,128}$`, false},
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/essentialkaos/scratch

go 1.17
go 1.18

require github.com/essentialkaos/ek/v12 v12.46.0
require github.com/essentialkaos/ek/v12 v12.63.0

require (
github.com/essentialkaos/go-linenoise/v3 v3.3.5 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect
golang.org/x/sys v0.6.0 // indirect
)
39 changes: 9 additions & 30 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0=
github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
github.com/essentialkaos/ek/v12 v12.46.0 h1:TNw9YmKPf67E9L886EzhH9xUO49bROqvqHR4bzOqf/E=
github.com/essentialkaos/ek/v12 v12.46.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo=
github.com/essentialkaos/go-linenoise/v3 v3.3.5 h1:gw3tJ3b5TPKFxNIXOTJuI+2Of+SgBAJBd8AidyNV9SI=
github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/ek/v12 v12.63.0 h1:9yaEu5W3bx//9y52ShqYCoFDKOcwEdrnvgSkUYyatgI=
github.com/essentialkaos/ek/v12 v12.63.0/go.mod h1:9MlSuHpewu7OZ9tM9dLFHvoA8dflBIUPCA0Ctt97wRs=
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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2 changes: 1 addition & 1 deletion scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
4 changes: 1 addition & 3 deletions templates/app/.github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ _Before opening an issue, search for similar bug reports or feature requests on

**System info:**

* **Version used (`{{SHORT_NAME}} --version`):**
* **OS (e.g. from `/etc/*-release`):**
* **Kernel (`uname -a`):**
* **Verbose version info (`{{SHORT_NAME}} -vv`):**
* **Install tools:**

**Steps to reproduce:**
Expand Down
24 changes: 20 additions & 4 deletions templates/app/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,34 @@ on:
branches: [master, develop]
pull_request:
branches: [master]
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SRC_DIR: src/github.com/${{ github.repository }}

jobs:
Go:
name: Go
runs-on: ubuntu-latest

env:
SRC_DIR: src/github.com/${{ github.repository }}

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

steps:
- name: Set up Go
Expand Down
Loading

0 comments on commit b044c87

Please sign in to comment.