Skip to content

Commit

Permalink
Merge pull request #478 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.126.0
  • Loading branch information
andyone authored Jun 10, 2024
2 parents 276944c + 77fdf62 commit e871ca2
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 381 deletions.
732 changes: 370 additions & 362 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func Hex2RGBA(h Hex) RGBA {
}

// RGB2Term converts RGB color to terminal color code
// https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors1
// https://github.com/essentialkaos/ek/tree/master/fmtc#88256-colors
func RGB2Term(c RGB) int {
R, G, B := int(c.R), int(c.G), int(c.B)

Expand All @@ -456,7 +456,7 @@ func RGB2Term(c RGB) int {
}

// Term2RGB converts terminal color code (0-255) to RGB color
// https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors1
// https://github.com/essentialkaos/ek/tree/master/fmtc#88256-colors
func Term2RGB(c uint8) RGB {
// Grayscale
if c > 231 {
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.125.1"
const VERSION = "12.126.0"

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

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/depsy v1.3.0
github.com/essentialkaos/go-linenoise/v3 v3.6.0
golang.org/x/crypto v0.23.0
golang.org/x/sys v0.20.0
golang.org/x/crypto v0.24.0
golang.org/x/sys v0.21.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4 changes: 4 additions & 0 deletions sortutil/natural.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (s naturalSlice) Less(i, j int) bool { return NaturalLess(s[i], s[j]) }
// StringsNatural sorts a slice of strings in natural order
// Limitation: only ASCII digits (0-9) are considered.
func StringsNatural(a []string) {
if len(a) <= 1 {
return
}

sort.Sort(naturalSlice(a))
}

Expand Down
4 changes: 4 additions & 0 deletions sortutil/sortutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *SortSuite) TestStringSorting(c *C) {
}

func (s *SortSuite) TestNaturalSorting(c *C) {
s0 := []string{"1"}

StringsNatural(s0)

s1 := []string{"abc5", "abc1", "abc01", "ab", "abc10", "abc2"}

StringsNatural(s1)
Expand Down
2 changes: 2 additions & 0 deletions support/support_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func (i *Info) printOSInfo() {
switch i.System.ContainerEngine {
case "docker":
format(12, true, "Container", "Yes (Docker)")
case "docker+runsc":
format(12, true, "Container", "Yes (Docker+gVisor)")
case "podman":
format(12, true, "Container", "Yes (Podman)")
case "lxc":
Expand Down
2 changes: 2 additions & 0 deletions support/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (s *SupportSuite) TestCollect(c *C) {

i.System.ContainerEngine = "docker"
i.printOSInfo()
i.System.ContainerEngine = "docker+runsc"
i.printOSInfo()
i.System.ContainerEngine = "podman"
i.printOSInfo()
i.System.ContainerEngine = "lxc"
Expand Down
18 changes: 14 additions & 4 deletions system/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

const (
DOCKER = "docker" // Docker (Moby)
PODMAN = "podman" // Podman
LXC = "lxc" // LXC
YANDEX = "yandex" // Yandex Serverless
DOCKER = "docker" // Docker (Moby)
PODMAN = "podman" // Podman
LXC = "lxc" // LXC
YANDEX = "yandex" // Yandex Serverless
DOCKER_RUNSC = "docker+runsc" // Docker (Moby) + runsc (gVisor)
)

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

// mountsFile is path to mounts file for init process
var mountsFile = "/proc/1/mounts"

// dockerEnv is path to env file inside a Docker container
var dockerEnv = "/.dockerenv"

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

// engineChecked set to true if engine was checked
Expand Down Expand Up @@ -64,13 +68,19 @@ func IsContainer() bool {

// guessEngine tries to guess container engine based on information from /proc/1/mounts
func guessEngine(mountsData string) string {
_, err := os.Stat(dockerEnv)

switch {
case strings.Contains(mountsData, "overlay-container /function/code/rootfs"):
return YANDEX
case strings.Contains(mountsData, "lxcfs "):
return LXC
case strings.Contains(mountsData, "workdir=/var/lib/containers"):
return PODMAN
case err == nil &&
strings.Contains(mountsData, "none /etc/hostname 9p") &&
strings.Contains(mountsData, "none /etc/hosts 9p"):
return DOCKER_RUNSC
case strings.Contains(mountsData, "workdir=/var/lib/docker"):
return DOCKER
}
Expand Down
12 changes: 12 additions & 0 deletions system/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var _ = Suite(&ContainerSuite{})
func (s *ContainerSuite) SetUpSuite(c *C) {
s.DataDir = c.MkDir()

os.WriteFile(s.DataDir+"/.dockerenv", []byte(``), 0644)

os.WriteFile(s.DataDir+"/default", []byte(`sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,nosuid,size=930048k,nr_inodes=232512,mode=755 0 0
Expand All @@ -50,6 +52,9 @@ tmpfs /dev tmpfs rw,seclabel,nosuid,size=65536k,mode=755 0 0`), 0644)
os.WriteFile(s.DataDir+"/podman", []byte(`overlay / overlay rw,context="system_u:object_r:container_file_t:s0:c858,c956",relatime,lowerdir=/var/lib/containers/storage/overlay/l/4WA73D64E37PLK3SAORPPUISJK,upperdir=/var/lib/containers/storage/overlay/5d57db59db9567665efd0e17756445580b53be42396198b35a94f10ff30416be/diff,workdir=/var/lib/containers/storage/overlay/5d57db59db9567665efd0e17756445580b53be42396198b35a94f10ff30416be/work,metacopy=on,volatile 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev tmpfs rw,context="system_u:object_r:container_file_t:s0:c858,c956",nosuid,noexec,size=65536k,mode=755,inode64 0 0`), 0644)

os.WriteFile(s.DataDir+"/docker-runsc", []byte(`none /etc/hosts 9p rw,trans=fd,rfdno=7,wfdno=7,aname=/,dfltuid=4294967294,dfltgid=4294967294,dcache=1000,cache=remote_revalidating,disable_fifo_open,directfs 0 0
none /etc/hostname 9p rw,trans=fd,rfdno=6,wfdno=6,aname=/,dfltuid=4294967294,dfltgid=4294967294,dcache=1000,cache=remote_revalidating,disable_fifo_open,directfs 0 0`), 0644)
}

func (s *ContainerSuite) TestGetEngine(c *C) {
Expand Down Expand Up @@ -77,6 +82,13 @@ func (s *ContainerSuite) TestGetEngine(c *C) {
mountsFile = s.DataDir + "/docker"
c.Assert(GetEngine(), Equals, DOCKER)

engineChecked = false
dockerEnv = s.DataDir + "/.dockerenv"

mountsFile = s.DataDir + "/docker-runsc"
c.Assert(GetEngine(), Equals, DOCKER_RUNSC)

dockerEnv = "/.dockerenv"
engineChecked = false

mountsFile = s.DataDir + "/podman"
Expand Down
41 changes: 38 additions & 3 deletions usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package usage
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"bytes"
"fmt"
"os"
"path/filepath"
Expand All @@ -31,6 +32,8 @@ const (

const _BREADCRUMBS_MIN_SIZE = 8

const _MAX_LINE_LENGTH = 88

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

const (
Expand Down Expand Up @@ -414,7 +417,7 @@ func (c *Command) Print() {
}

fmtc.Print(getSeparator(size, maxSize, useBreadcrumbs))
fmtc.Print(c.Desc)
fmtc.Print(wrapText(c.Desc, maxSize+2))

fmtc.NewLine()
}
Expand Down Expand Up @@ -447,7 +450,7 @@ func (o *Option) Print() {
}

fmtc.Print(getSeparator(size, maxSize, useBreadcrumbs))
fmtc.Print(o.Desc)
fmtc.Print(wrapText(o.Desc, maxSize+5))

fmtc.NewLine()
}
Expand Down Expand Up @@ -477,7 +480,7 @@ func (e *Example) Print() {
e.info.ExampleDescColorTag, "",
), DEFAULT_EXAMPLE_DESC_COLOR_TAG,
)
fmtc.Printf(" "+descColor+"%s{!}\n", e.Desc)
fmtc.Printf(" "+descColor+"%s{!}\n", wrapText(e.Desc, 2))
}
}

Expand Down Expand Up @@ -810,3 +813,35 @@ func printNewVersionInfo(curVersion, newVersion string, releaseDate time.Time) {
fmtc.Printf("{s-}(released %d days ago){!}\n", days)
}
}

// wrapText wraps long text
func wrapText(text string, indent int) string {
size := _MAX_LINE_LENGTH - indent

if strutil.LenVisual(fmtc.Clean(text)) <= size {
return text
}

var buf bytes.Buffer

for {
if len(text) < size {
buf.WriteString(text)
break
}

wi := strings.LastIndex(text[:size], " ")

if wi == -1 {
buf.WriteString(text)
break
}

buf.WriteString(text[:wi])
buf.WriteRune('\n')
buf.WriteString(strings.Repeat(" ", indent))
text = text[wi+1:]
}

return buf.String()
}
6 changes: 3 additions & 3 deletions usage/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ func (s *UsageSuite) TestUsage(c *C) {
info.AddCommand("read")
info.AddCommand("read", "Read command")
info.AddCommand("read1", "Read command with arguments", "arg1", "arg2")
info.AddCommand("read2", "Read command with optional argument", "?arg")
info.AddCommand("read2", "Read command with optional argument and very very very {*b}long{!} and {c}colored{!} description", "?arg")

info.AddOption("t:test")
info.AddOption("t:test", "Test option ")
info.AddOption("test1", "Test option with argument", "arg")
info.AddOption("test2", "Test option with optional argument", "?arg")
info.AddOption("test2", "Test option with optional argument and very very very {*b}long{!} and {c}colored{!} description", "?arg")

info.BoundOptions("read", "t:test", "test1")

info.AddExample() // will be ignored
info.AddExample("abc")
info.AddExample("abc", "Example with description")
info.AddExample("abc", "Example with very long description that not fits default 88 symbols limit and link https://domain.com/#EC103814B9CCB1E305CE20D6A25E681D3735D2301D5BB631B8DFA0ABB2394A99631B8DFA0ABB2394A99")
info.AddRawExample() // will be ignored
info.AddRawExample("echo 123 | myapp")
info.AddRawExample("echo 123 | myapp", "Example with description")
Expand Down

0 comments on commit e871ca2

Please sign in to comment.