Skip to content

Commit

Permalink
Merge pull request #62 from tongson/unsafe_cupcake
Browse files Browse the repository at this point in the history
Unsafe cupcake
  • Loading branch information
tongson authored Jul 4, 2024
2 parents 372ff87 + f876d88 commit 85daf0d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md → README.d/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#### 2.2.1

Unsafe Cupcake

* Fix output during parallel runs
* Print README* file when no `namespace:script` specified
* Include `.lib` in `rrd` (dump) mode

#### 2.2.0

Craving Detonator
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# rr
# taarr

Check out the documentation at [taarr.com](https://taarr.com)

Expand Down
6 changes: 3 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

const cVERSION = "2.2.0"
const cCODE = "Craving Detonator"
const cVERSION = "2.2.1"
const cCODE = "Unsafe Cupcake"

const cOP = "LOG"
const cINC = "VARS"
Expand All @@ -20,7 +20,7 @@ const cSTDERR = " ┌─ stderr"
const cSTDDBG = " ┌─ debug"
const cFOOTER = " └─"

const cANSI = "\x1b[0036m%s\x1b[0000m"
const cANSI = "\x1b[1G\x1b[0036m%s\x1b[0000m %s"

const cTARC = "--no-same-owner --no-same-permissions"
const cTARX = "--no-same-owner --no-same-permissions --no-overwrite-dir --no-acls --no-selinux --no-xattrs --touch"
Expand Down
46 changes: 33 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func getPassword(prompt string) (string, error) {
}

func (writer logWriter) Write(bytes []byte) (int, error) {
fmt.Printf(cANSI, time.Now().Format(time.RFC822Z))
return fmt.Print(" " + string(bytes))
return fmt.Printf(cANSI, time.Now().Format(time.RFC822Z), string(bytes))
}

func soOutput(h string, m int) func(string) {
Expand Down Expand Up @@ -553,7 +552,7 @@ rrl = report`
if isatty.IsTerminal(os.Stdout.Fd()) {
opt.mode = oTerm
log.SetOutput(new(logWriter))
log.Printf("rr %s “%s”", cVERSION, cCODE)
log.Printf("taarr %s “%s”", cVERSION, cCODE)
} else {
serrLog = slog.New(slog.NewJSONHandler(os.Stderr, nil))
}
Expand All @@ -563,6 +562,34 @@ rrl = report`
var id string = generateHashId()
opt.id = id // used for the random suffix in the temp filename
if len(os.Args) < 2 {
isReadme := func() (bool, string) {
match, _ := lib.FileGlob("README*")
for _, m := range match {
if lib.IsFile(m) {
return true, m
}
}
return false, ""
}
printReadme := func(s string) {
switch opt.mode {
case oTerm:
for _, each := range lib.FileLines(s) {
fmt.Printf(" \033[38;2;85;85;85m⋮\033[0m %s\n", each)
}
fmt.Printf("\n")
case oPlain:
fmt.Print(lib.FileRead(s))
case oJson:
serrLog.Error("README output disabled in this mode.")
os.Exit(2)
}
}
if found1, readme1 := isReadme(); found1 && readme1 != "" {
log.Printf("Showing %s…", readme1)
printReadme(readme1)
os.Exit(0)
}
switch opt.mode {
case oJson:
serrLog.Error(eUNSPECIFIED)
Expand Down Expand Up @@ -652,6 +679,7 @@ rrl = report`
var namespace string
var script string
var nsScript string
var dumpLib string
var code string
var interp string
var opLog string
Expand All @@ -666,16 +694,6 @@ rrl = report`
if len(s) < 2 {
s = strings.Split(os.Args[offset], ":")
}
if len(s) < 2 {
switch opt.mode {
case oTerm, oPlain:
_, _ = fmt.Fprintln(os.Stderr, eUNSPECIFIED)
os.Exit(2)
case oJson:
serrLog.Error("namespace:script not specified")
os.Exit(2)
}
}
namespace, script = s[0], s[1]
if !lib.IsDir(namespace) {
switch opt.mode {
Expand Down Expand Up @@ -744,6 +762,7 @@ rrl = report`
os.Exit(255)
}
}
dumpLib = sh.String()
if opt.sudo {
if !opt.nopasswd {
str, err := getPassword("sudo password: ")
Expand Down Expand Up @@ -784,6 +803,7 @@ rrl = report`

// rrd mode
if mDump {
fmt.Print(dumpLib)
fmt.Print(code)
os.Exit(0)
}
Expand Down
1 change: 1 addition & 0 deletions make/update/script
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
go get -u
go get -u=patch
go mod tidy
go mod verify
Empty file.

0 comments on commit 85daf0d

Please sign in to comment.