Skip to content

Commit

Permalink
Merge pull request #43 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.0.11
  • Loading branch information
andyone authored Dec 25, 2023
2 parents b044c87 + 256eab9 commit c71c1a2
Show file tree
Hide file tree
Showing 47 changed files with 560 additions and 250 deletions.
57 changes: 36 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,57 @@ 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

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

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

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

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
id: go

- name: Setup PATH
run: |
echo "GOPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
echo "GOBIN=${{ github.workspace }}/bin" >> "$GITHUB_ENV"
echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH"
- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Build binary
working-directory: ${{env.SRC_DIR}}
- name: Run tests
run: make all

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
5 changes: 5 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[files]
extend-exclude = ["go.sum"]

[default.extend-identifiers]
O_WRONLY = "O_WRONLY"
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<p align="center">
<a href="https://kaos.sh/w/scratch/ci"><img src="https://kaos.sh/w/scratch/ci.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/r/scratch"><img src="https://kaos.sh/r/scratch.svg" alt="GoReportCard" /></a>
<a href="https://kaos.sh/b/scratch"><img src="https://kaos.sh/b/3b2ed0f2-1e39-4366-93f6-d955ca22ce3a.svg" alt="Codebeat badge" /></a>
<a href="https://kaos.sh/w/scratch/codeql"><img src="https://kaos.sh/w/scratch/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
Expand All @@ -18,7 +17,7 @@

#### From sources

To install the `scratch` from sources, make sure you have a working Go 1.19+ 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://go.dev/doc/install)_), then:

```
go install github.com/essentialkaos/scratch
Expand Down Expand Up @@ -70,10 +69,10 @@ Examples
List files in template "package"
scratch package .
Generate files based on tempalte "package" in current directory
Generate files based on template "package" in current directory
scratch service $GOPATH/src/github.com/essentialkaos/myapp
Generate files based on tempalte "service" in given directory
Generate files based on template "service" in given directory
```

### Contributing
Expand Down
56 changes: 21 additions & 35 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ const (

var optMap = options.Map{
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VER: {Type: options.BOOL, Alias: "ver"},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_COMPLETION: {},
OPT_GENERATE_MAN: {Type: options.BOOL},
}

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

// Init is main app func
func Init() {
// Run is main utility function
func Run() {
preConfigureUI()

args, errs := options.Parse(optMap)
Expand All @@ -80,13 +80,16 @@ func Init() {

switch {
case options.Has(OPT_COMPLETION):
os.Exit(genCompletion())
os.Exit(printCompletion())
case options.Has(OPT_GENERATE_MAN):
os.Exit(genMan())
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
os.Exit(showAbout())
genAbout().Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_HELP):
os.Exit(showUsage())
genUsage().Print()
os.Exit(0)
}

switch len(args) {
Expand Down Expand Up @@ -340,20 +343,8 @@ func printErrorAndExit(f string, a ...interface{}) {

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

// showUsage prints usage info
func showUsage() int {
genUsage().Render()
return 0
}

// showAbout prints info about version
func showAbout() int {
genAbout().Render()
return 0
}

// genCompletion generates completion for different shells
func genCompletion() int {
// printCompletion prints completion for given shell
func printCompletion() int {
info := genUsage()

switch options.GetS(OPT_COMPLETION) {
Expand All @@ -370,16 +361,9 @@ func genCompletion() int {
return 0
}

// genMan generates man page
func genMan() int {
fmt.Println(
man.Generate(
genUsage(),
genAbout(),
),
)

return 0
// printMan prints man page
func printMan() {
fmt.Println(man.Generate(genUsage(), genAbout()))
}

// genUsage generates usage info
Expand All @@ -393,19 +377,19 @@ func genUsage() *usage.Info {
info.AddExample("package", "List files in template \"package\"")
info.AddExample(
"package .",
"Generate files based on tempalte \"package\" in current directory",
"Generate files based on template \"package\" in current directory",
)
info.AddExample(
"service $GOPATH/src/github.com/essentialkaos/myapp",
"Generate files based on tempalte \"service\" in given directory",
"Generate files based on template \"service\" in given directory",
)

return info
}

// genAbout generates info about version
func genAbout() *usage.About {
return &usage.About{
about := &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Expand All @@ -414,6 +398,8 @@ func genAbout() *usage.About {
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/" + APP, update.GitHubChecker},
}

return about
}

// ////////////////////////////////////////////////////////////////////////////////// //
9 changes: 6 additions & 3 deletions app/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
VAR_DESC = "DESC"
VAR_DESC_README = "DESC_README"

VAR_CODEBEAT_UUID = "CODEBEAT_UUID"
VAR_CODEBEAT_UUID = "CODEBEAT_UUID"
VAR_CODECLIMATE_ID = "CODECLIMATE_ID"

VAR_SHORT_NAME_TITLE = "SHORT_NAME_TITLE"
VAR_SHORT_NAME_LOWER = "SHORT_NAME_LOWER"
Expand All @@ -45,7 +46,7 @@ const (
type Variables map[string]string // name → value

type Template struct {
Name string // Name of tempate
Name string // Name of template
Path string // Path to directory with template data

Vars Variables // Variables
Expand Down Expand Up @@ -74,7 +75,8 @@ var knownVars = &VariableInfoStore{
VAR_DESC: {"Description", `^.{16,128}$`, false},
VAR_DESC_README: {"Description for README file (part after 'app is… ')", `^.{16,128}$`, false},

VAR_CODEBEAT_UUID: {"Codebeat project UUID", ``, false},
VAR_CODEBEAT_UUID: {"Codebeat project UUID", ``, false},
VAR_CODECLIMATE_ID: {"Code climate project ID", ``, false},

VAR_SHORT_NAME_TITLE: {"Short name in title case", ``, true},
VAR_SHORT_NAME_LOWER: {"Short name in lower case", ``, true},
Expand All @@ -90,6 +92,7 @@ var knownVars = &VariableInfoStore{
VAR_DESC,
VAR_DESC_README,
VAR_CODEBEAT_UUID,
VAR_CODECLIMATE_ID,
},
}

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

go 1.18

require github.com/essentialkaos/ek/v12 v12.63.0
require (
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.92.0
)

require (
github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.92.0 h1:3JIkHWNA6MNkJOfqzMWJ8jN9sRM7nRi7URoFRVFHZzI=
github.com/essentialkaos/ek/v12 v12.92.0/go.mod h1:9efMqo1S8EtYhmeelOSTmMQDGC2vRgPkjkKKfvUD2eU=
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/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=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2 changes: 1 addition & 1 deletion scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
APP.Init()
APP.Run()
}
39 changes: 39 additions & 0 deletions templates/app/.codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "2"

checks:
argument-count:
enabled: true
config:
threshold: 6
complex-logic:
enabled: true
config:
threshold: 6
file-lines:
enabled: true
config:
threshold: 1000
method-complexity:
enabled: true
config:
threshold: 8
method-count:
enabled: true
config:
threshold: 20
method-lines:
enabled: true
config:
threshold: 100
nested-control-flow:
enabled: true
config:
threshold: 6
return-statements:
enabled: true
config:
threshold: 6
similar-code:
enabled: false
identical-code:
enabled: false
Loading

0 comments on commit c71c1a2

Please sign in to comment.