Skip to content

Commit

Permalink
Merge pull request #91 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
andyone authored Aug 12, 2023
2 parents 80fa353 + 84f29d0 commit 70a1575
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 48 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ To build the `aligo` from scratch, make sure you have a working Go 1.18+ workspa
go install github.com/essentialkaos/aligo@latest
```

#### Using with Github Actions

For using _aligo_ with Github Actions use this workflow file or add job `Aligo` to your workflow:

```yml
name: Aligo

on:
push:
branches: [master, develop]
pull_request:
branches: [master]

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

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

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20.x'

- name: Check Golang sources with Aligo
uses: essentialkaos/aligo-action@v2
with:
files: ./...
```
### Command-line completion
You can generate completion for `bash`, `zsh` or `fish` shell.
Expand All @@ -40,21 +73,19 @@ Bash:
sudo aligo --completion=bash 1> /etc/bash_completion.d/aligo
```


ZSH:
```bash
sudo aligo --completion=zsh 1> /usr/share/zsh/site-functions/aligo
```


Fish:
```bash
sudo aligo --completion=fish 1> /usr/share/fish/vendor_completions.d/aligo.fish
```

### Man documentation

You can generate man page for aligo using next command:
You can generate man page for _aligo_ using next command:

```bash
aligo --generate-man | sudo gzip > /usr/share/man/man1/aligo.1.gz
Expand Down
24 changes: 3 additions & 21 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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 @@ -36,7 +35,7 @@ import (
// App info
const (
APP = "aligo"
VER = "2.0.0"
VER = "2.0.1"
DESC = "Utility for viewing and checking Golang struct alignment"
)

Expand All @@ -63,7 +62,7 @@ var optMap = options.Map{
OPT_TAGS: {Mergeble: true},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
Expand Down Expand Up @@ -94,7 +93,7 @@ func Run(gitRev string, gomod []byte) {
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
genAbout(gitRev).Print()
genAbout(gitRev).Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.Print(APP, VER, gitRev, gomod)
Expand All @@ -110,23 +109,6 @@ func Run(gitRev string, gomod []byte) {

// 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
}
Expand Down
32 changes: 10 additions & 22 deletions cli/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package cli

import (
"fmt"
"path/filepath"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
Expand All @@ -22,11 +21,6 @@ import (

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

// MAX_TYPE_SIZE maximum type size
const MAX_TYPE_SIZE = 32

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

type Renderer struct {
format string
hasTags bool
Expand Down Expand Up @@ -103,11 +97,11 @@ func NewRenderer(fields []*report.Field, detailed bool) *Renderer {

var mName, mType, mTag, mComm int

for _, field := range fields {
mName = mathutil.Max(mName, len(field.Name))
mType = mathutil.Max(mType, len(filepath.Base(field.Type))+1)
mTag = mathutil.Max(mTag, len(field.Tag))
mComm = mathutil.Max(mComm, len(field.Comment))
for _, f := range fields {
mName = mathutil.Max(mName, len(f.Name))
mType = mathutil.Max(mType, len(f.Type))
mTag = mathutil.Max(mTag, len(f.Tag))
mComm = mathutil.Max(mComm, len(f.Comment))
}

if mTag > 0 {
Expand Down Expand Up @@ -146,7 +140,7 @@ func NewRenderer(fields []*report.Field, detailed bool) *Renderer {

// PrintField prints field info
func (r *Renderer) PrintField(f *report.Field) {
var fTag, fComment, fType string
var fTag, fComment string

if f.Tag != "" {
fTag = "`" + f.Tag + "`"
Expand All @@ -158,21 +152,15 @@ func (r *Renderer) PrintField(f *report.Field) {
fComment = f.Comment
}

fType = filepath.Base(f.Type)

if strings.HasPrefix(f.Type, "*") {
fType = "*" + fType
}

switch {
case r.hasTags && r.hasComments:
fmtc.Printf(r.format, f.Name, fType, fTag, fComment)
fmtc.Printf(r.format, f.Name, f.Type, fTag, fComment)
case r.hasTags && !r.hasComments:
fmtc.Printf(r.format, f.Name, fType, fTag)
fmtc.Printf(r.format, f.Name, f.Type, fTag)
case !r.hasTags && r.hasComments:
fmtc.Printf(r.format, f.Name, fType, fComment)
fmtc.Printf(r.format, f.Name, f.Type, fComment)
default:
fmtc.Printf(r.format, f.Name, fType)
fmtc.Printf(r.format, f.Name, f.Type)
}
}

Expand Down
22 changes: 22 additions & 0 deletions cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"runtime"
"runtime/debug"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
Expand Down Expand Up @@ -55,6 +56,10 @@ func showApplicationInfo(app, ver, gitRev string) {
runtime.GOOS, runtime.GOARCH,
))

if gitRev == "" {
gitRev = extractGitRevFromBuildInfo()
}

if gitRev != "" {
if !fmtc.DisableColors && fmtc.IsTrueColorSupported() {
printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev))
Expand Down Expand Up @@ -114,6 +119,23 @@ func showDepsInfo(gomod []byte) {
}
}

// extractGitRevFromBuildInfo extracts git SHA from embeded build info
func extractGitRevFromBuildInfo() string {
info, ok := debug.ReadBuildInfo()

if !ok {
return ""
}

for _, s := range info.Settings {
if s.Key == "vcs.revision" && len(s.Value) > 7 {
return s.Value[:7]
}
}

return ""
}

// getHashColorBullet return bullet with color from hash
func getHashColorBullet(v string) string {
if len(v) > 6 {
Expand Down
1 change: 1 addition & 0 deletions cli/support/support_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func showOSInfo() {
printInfo(12, "ID Like", osInfo.IDLike)
printInfo(12, "Version ID", osInfo.VersionID)
printInfo(12, "Version Code", osInfo.VersionCodename)
printInfo(12, "Platform ID", osInfo.PlatformID)
printInfo(12, "CPE", osInfo.CPEName)
}

Expand Down
8 changes: 6 additions & 2 deletions inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func processPackage(pkg *packages.Package) (*report.Package, error) {
}

case *ast.ImportSpec:
ntPath := strings.Trim(nt.Path.Value, "\"")
ntPath := strings.Trim(nt.Path.Value, `"`)

if strings.Contains(ntPath, "/") {
if nt.Name == nil {
Expand Down Expand Up @@ -239,10 +239,14 @@ func convertPosition(pos token.Position) report.Position {
func formatValueType(typ string, mappings map[string]string) string {
for k, v := range mappings {
if strings.Contains(typ, k) {
return strings.Replace(typ, k, v, -1)
typ = strings.ReplaceAll(typ, k, v)
}
}

if strings.ContainsRune(typ, '/') {
return path.Base(typ)
}

return typ
}

Expand Down

0 comments on commit 70a1575

Please sign in to comment.