Skip to content

Commit

Permalink
Merge pull request #61 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.6.1
  • Loading branch information
andyone committed Mar 24, 2023
2 parents 87d92d6 + 7c53d55 commit afea246
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 153 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -7,6 +7,22 @@ on:
branches: [master]
schedule:
- cron: '0 18 * * 0'
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 }}
Expand All @@ -18,11 +34,11 @@ jobs:

strategy:
matrix:
go: [ '1.18.x', '1.19.x' ]
go: [ '1.18.x', '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 }}

Expand All @@ -47,9 +63,9 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: '1.18.x'
go-version: '1.19.x'

- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -25,10 +25,10 @@

#### From source

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

```
go install github.com/essentialkaos/aligo
go install github.com/essentialkaos/aligo@latest
```

### Command-line completion
Expand Down
4 changes: 2 additions & 2 deletions aligo.go
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 All @@ -24,5 +24,5 @@ var gitrev string
// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
CLI.Init(gitrev, gomod)
CLI.Run(gitrev, gomod)
}
85 changes: 48 additions & 37 deletions cli/cli.go
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// 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 @@ -17,6 +17,7 @@ import (

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/usage"
Expand All @@ -26,16 +27,16 @@ import (
"github.com/essentialkaos/ek/v12/usage/man"
"github.com/essentialkaos/ek/v12/usage/update"

"github.com/essentialkaos/aligo/cli/support"
"github.com/essentialkaos/aligo/inspect"
"github.com/essentialkaos/aligo/support"
)

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

// App info
const (
APP = "aligo"
VER = "1.6.0"
VER = "1.6.1"
DESC = "Utility for viewing and checking Golang struct alignment"
)

Expand All @@ -61,8 +62,8 @@ var optMap = options.Map{
OPT_STRUCT: {},
OPT_TAGS: {Mergeble: true},
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.BOOL},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
Expand All @@ -71,44 +72,66 @@ var optMap = options.Map{

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

// Init is main CLI func
func Init(gitRev string, gomod []byte) {
// Run is main CLI function
func Run(gitRev string, gomod []byte) {
runtime.GOMAXPROCS(2)

preConfigureUI()

args, errs := options.Parse(optMap)

if len(errs) != 0 {
printError("Options parsing errors:")

for _, err := range errs {
printError(" %v", err)
}

printError(errs[0].Error())
os.Exit(1)
}

configureUI()

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):
showAbout(gitRev)
return
genAbout(gitRev).Print()
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.ShowSupportInfo(APP, VER, gitRev, gomod)
return
support.Print(APP, VER, gitRev, gomod)
os.Exit(0)
case options.GetB(OPT_HELP) || len(args) < 2:
showUsage()
return
genUsage().Print()
os.Exit(0)
}

prepare()
process(args)
}

// 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") == "" {
fmtc.DisableColors = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configures user interface
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
Expand Down Expand Up @@ -190,18 +213,8 @@ func printErrorAndExit(f string, a ...interface{}) {

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

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

// showAbout prints info about version
func showAbout(gitRev string) {
genAbout(gitRev).Render()
}

// 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 @@ -218,16 +231,14 @@ func genCompletion() int {
return 0
}

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

return 0
}

// genUsage generates usage info
Expand Down
2 changes: 1 addition & 1 deletion cli/render.go
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// 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
51 changes: 24 additions & 27 deletions support/support.go → cli/support/support.go
Expand Up @@ -2,14 +2,15 @@ package support

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

import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"

Expand All @@ -23,27 +24,17 @@ import (

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

// Pkg contains basic package info
type Pkg struct {
Name string
Version string
}

// Pkgs is slice with packages
type Pkgs []Pkg

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

// ShowSupportInfo prints verbose info about application, system, dependencies and
// Print prints verbose info about application, system, dependencies and
// important environment
func ShowSupportInfo(app, ver, gitRev string, gomod []byte) {
func Print(app, ver, gitRev string, gomod []byte) {
fmtutil.SeparatorTitleColorTag = "{s-}"
fmtutil.SeparatorFullscreen = false
fmtutil.SeparatorColorTag = "{s-}"
fmtutil.SeparatorSize = 80

showApplicationInfo(app, ver, gitRev)
showOSInfo()
showEnvInfo()
showDepsInfo(gomod)

fmtutil.Separator(false)
Expand Down Expand Up @@ -85,6 +76,25 @@ func showApplicationInfo(app, ver, gitRev string) {
}
}

// showEnvInfo shows info about environment
func showEnvInfo() {
fmtutil.Separator(false, "ENVIRONMENT")

cmd := exec.Command("go", "version")
out, err := cmd.Output()

if err != nil {
printInfo(2, "Go", "")
return
}

goVer := string(out)
goVer = strutil.ReadField(goVer, 2, false, " ")
goVer = strutil.Exclude(goVer, "go")

printInfo(2, "Go", goVer)
}

// showDepsInfo shows information about all dependencies
func showDepsInfo(gomod []byte) {
deps := depsy.Extract(gomod, false)
Expand Down Expand Up @@ -128,16 +138,3 @@ func printInfo(size int, name, value string) {
}

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

// getMaxSize returns max package name size
func (p Pkgs) getMaxSize() int {
size := 0

for _, pkg := range p {
if len(pkg.Name) > size {
size = len(pkg.Name)
}
}

return size
}
23 changes: 11 additions & 12 deletions support/support_darwin.go → cli/support/support_darwin.go
Expand Up @@ -2,7 +2,7 @@ package support

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// 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 @@ -22,20 +22,19 @@ func showOSInfo() {
return
}

osInfo, err := system.GetOSInfo()

if err == nil {
fmtutil.Separator(false, "OS INFO")

printInfo(12, "Name", osInfo.Name)
printInfo(12, "Version", osInfo.VersionID)
printInfo(12, "Build", osInfo.Build)
}

fmtutil.Separator(false, "SYSTEM INFO")

printInfo(7, "Name", systemInfo.OS)
printInfo(7, "Version", systemInfo.Version)
printInfo(7, "Arch", systemInfo.Arch)
printInfo(7, "Kernel", systemInfo.Kernel)
}

// collectEnvInfo collects info about environment
func collectEnvInfo() Pkgs {
return nil
}

// showEnvInfo shows info about environment
func showEnvInfo(pkgs Pkgs) {
return
}

0 comments on commit afea246

Please sign in to comment.