mirror of https://github.com/rwxrob/bonzai
parent
466c7a3062
commit
449467d78a
@ -0,0 +1,52 @@
|
||||
package cmd
|
||||
|
||||
/*
|
||||
var Help = &Z.Cmd{
|
||||
Name: `help`,
|
||||
Aliases: []string{"h"},
|
||||
Call: func(x *Z.Cmd, args ...string) error {
|
||||
|
||||
var buf string
|
||||
|
||||
buf += util.Emph("**NAME**", 0, -1) + "\n " + x.Title() + "\n\n"
|
||||
buf += util.Emph("**SYNOPSIS**", 0, -1) + "\n " + x.Name + " " + x.Usage + "\n\n"
|
||||
|
||||
if len(x.Commands.M) > 0 {
|
||||
buf += util.Emph("**COMMANDS**", 0, -1) + "\n" + x.Titles(7, 20) + "\n\n"
|
||||
}
|
||||
|
||||
if len(x.Description) > 0 {
|
||||
buf +=
|
||||
util.Emph("**DESCRIPTION**", 0, -1) + "\n" +
|
||||
util.Emph(x.Description, 7, 65) + "\n\n"
|
||||
}
|
||||
|
||||
if x.Source != "" || x.Issues != "" || x.Site != "" {
|
||||
|
||||
buf += util.Emph("**LINKS**", 0, -1) + "\n"
|
||||
|
||||
if x.Site != "" {
|
||||
buf += " Site: " + x.Site + "\n"
|
||||
}
|
||||
|
||||
if x.Source != "" {
|
||||
buf += " Source: " + x.Source + "\n"
|
||||
}
|
||||
|
||||
if x.Issues != "" {
|
||||
buf += " Issues: " + x.Issues + "\n"
|
||||
}
|
||||
|
||||
buf += "\n"
|
||||
|
||||
}
|
||||
|
||||
if x.Copyright != "" {
|
||||
buf += util.Emph("**LEGAL**", 0, -1) + "\n" + util.Indent(x.Legal(), 7) + "\n\n"
|
||||
}
|
||||
|
||||
return buf
|
||||
|
||||
},
|
||||
}
|
||||
*/
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
Package loop shamelessly attempts to bring the better parts of Lisp loops to Go specifically in order to enable rapid, and clean applications development --- particularly when replacing shell scripts with Go.
|
||||
*/
|
||||
package loop
|
||||
|
||||
import "fmt"
|
||||
|
||||
// All executes the given function for every item in the slice.
|
||||
func All[T any](set []T, p func(i T)) {
|
||||
for _, i := range set {
|
||||
p(i)
|
||||
}
|
||||
}
|
||||
|
||||
// UntilError executes the give function for every item in the slice
|
||||
// until it encounters and error and returns the error, if any.
|
||||
func UntilError[T any](set []T, p func(i T) error) error {
|
||||
for _, i := range set {
|
||||
if err := p(i); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Println prints ever element of the set.
|
||||
func Println[T any](set []T) {
|
||||
All(set, func(i T) { fmt.Println(i) })
|
||||
}
|
||||
|
||||
// Print prints ever element of the set.
|
||||
func Print[T any](set []T) {
|
||||
All(set, func(i T) { fmt.Print(i) })
|
||||
}
|
||||
|
||||
// Printf prints ever element of the set using format string.
|
||||
func Printf[T any](set []T, form string) {
|
||||
All(set, func(i T) { fmt.Printf(form, i) })
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package loop_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rwxrob/bonzai/loop"
|
||||
)
|
||||
|
||||
func ExampleAll() {
|
||||
set1 := []string{"doe", "ray", "mi"}
|
||||
loop.All(set1, func(s string) { fmt.Print(s) })
|
||||
fmt.Println()
|
||||
f1 := func() { fmt.Print("one") }
|
||||
f2 := func() { fmt.Print("two") }
|
||||
f3 := func() { fmt.Print("three") }
|
||||
set2 := []func(){f1, f2, f3}
|
||||
loop.All(set2, func(f func()) { f() })
|
||||
// Output:
|
||||
// doeraymi
|
||||
// onetwothree
|
||||
}
|
||||
|
||||
func ExamplePrintln() {
|
||||
set := []string{"doe", "ray", "mi"}
|
||||
loop.Println(set)
|
||||
bools := []bool{false, true, true}
|
||||
loop.Println(bools)
|
||||
// Output:
|
||||
// doe
|
||||
// ray
|
||||
// mi
|
||||
// false
|
||||
// true
|
||||
// true
|
||||
}
|
||||
|
||||
func ExamplePrint() {
|
||||
set := []string{"doe", "ray", "mi"}
|
||||
loop.Print(set)
|
||||
bools := []bool{false, true, true}
|
||||
loop.Print(bools)
|
||||
// Output:
|
||||
// doeraymifalsetruetrue
|
||||
}
|
||||
|
||||
func ExamplePrintf() {
|
||||
set := []string{"doe", "ray", "mi"}
|
||||
loop.Printf(set, "sing %v\n")
|
||||
// Output:
|
||||
// sing doe
|
||||
// sing ray
|
||||
// sing mi
|
||||
}
|
Loading…
Reference in New Issue