Skip to content

Commit

Permalink
Merge pull request #87 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
andyone authored Mar 27, 2024
2 parents c71c1a2 + 8bed0a7 commit 3f16cbd
Show file tree
Hide file tree
Showing 36 changed files with 203 additions and 225 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.20.x', '1.21.x' ]
go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x' ]

steps:
- name: Checkout
Expand Down
73 changes: 44 additions & 29 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -11,7 +11,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
Expand All @@ -21,7 +20,11 @@ import (
"github.com/essentialkaos/ek/v12/path"
"github.com/essentialkaos/ek/v12/pluralize"
"github.com/essentialkaos/ek/v12/sortutil"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/apps"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
"github.com/essentialkaos/ek/v12/usage/completion/fish"
Expand All @@ -34,7 +37,7 @@ import (

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

Expand All @@ -45,6 +48,7 @@ const (
OPT_HELP = "h:help"
OPT_VER = "v:version"

OPT_VERB_VER = "vv:verbose-version"
OPT_COMPLETION = "completion"
OPT_GENERATE_MAN = "generate-man"
)
Expand All @@ -56,14 +60,17 @@ var optMap = options.Map{
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

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

var colorTagApp, colorTagVer string

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

// Run is main utility function
func Run() {
func Run(gitRev string, gomod []byte) {
preConfigureUI()

args, errs := options.Parse(optMap)
Expand All @@ -85,7 +92,13 @@ func Run() {
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
genAbout().Print(options.GetS(OPT_VER))
genAbout(gitRev).Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.Collect(APP, VER).WithRevision(gitRev).
WithDeps(deps.Extract(gomod)).
WithApps(apps.Golang()).Print()
os.Exit(0)
os.Exit(0)
case options.GetB(OPT_HELP):
genUsage().Print()
Expand All @@ -107,25 +120,17 @@ func Run() {

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

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

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
switch {
case fmtc.IsTrueColorSupported():
colorTagApp, colorTagVer = "{*}{&}{#F4BA33}", "{#F4BA33}"
case fmtc.Is256ColorsSupported():
colorTagApp, colorTagVer = "{*}{&}{#220}", "{#220}"
default:
colorTagApp, colorTagVer = "{*}{&}{y}", "{y}"
}
}

Expand Down Expand Up @@ -363,7 +368,7 @@ func printCompletion() int {

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

// genUsage generates usage info
Expand All @@ -388,15 +393,25 @@ func genUsage() *usage.Info {
}

// genAbout generates info about version
func genAbout() *usage.About {
func genAbout(gitRev string) *usage.About {
about := &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Year: 2006,
Owner: "ESSENTIAL KAOS",
App: APP,
Version: VER,
Desc: DESC,
Year: 2009,
Owner: "ESSENTIAL KAOS",

AppNameColorTag: colorTagApp,
VersionColorTag: colorTagVer,
DescSeparator: "{s}—{!}",

License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/" + APP, update.GitHubChecker},
BugTracker: "https://github.com/essentialkaos/{{SHORT_NAME}}/issues",
UpdateChecker: usage.UpdateChecker{"essentialkaos/{{SHORT_NAME}}", update.GitHubChecker},
}

if gitRev != "" {
about.Build = "git:" + gitRev
}

return about
Expand Down
2 changes: 1 addition & 1 deletion app/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
8 changes: 3 additions & 5 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.92.0
)
require github.com/essentialkaos/ek/v12 v12.111.1

require (
github.com/essentialkaos/depsy v1.1.0 // indirect
github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
)
8 changes: 4 additions & 4 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.92.0 h1:3JIkHWNA6MNkJOfqzMWJ8jN9sRM7nRi7URoFRVFHZzI=
github.com/essentialkaos/ek/v12 v12.92.0/go.mod h1:9efMqo1S8EtYhmeelOSTmMQDGC2vRgPkjkKKfvUD2eU=
github.com/essentialkaos/ek/v12 v12.111.1 h1:s9vi+ydPmt1MI/JtABqmfD32j1VMFsZHe/45eAC+XYU=
github.com/essentialkaos/ek/v12 v12.111.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U=
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.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=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14 changes: 12 additions & 2 deletions scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ package main

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
_ "embed"

APP "github.com/essentialkaos/scratch/app"
)

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

//go:embed go.mod
var gomod []byte

// gitrev is short hash of the latest git commit
var gitrev string

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

func main() {
APP.Run()
APP.Run(gitrev, gomod)
}
4 changes: 2 additions & 2 deletions templates/app/.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.20.x', '1.21.x' ]
go: [ '1.21.x', '1.22.x' ]

steps:
- name: Checkout
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
2 changes: 2 additions & 0 deletions templates/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{SHORT_NAME}}
vendor
2 changes: 1 addition & 1 deletion templates/app/_name_.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
Loading

0 comments on commit 3f16cbd

Please sign in to comment.