Drop loop

pull/53/head v0.0.9
rwxrob 2 years ago
parent 466c7a3062
commit 449467d78a
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -8,7 +8,7 @@ import (
"os"
"github.com/rwxrob/bonzai/comp"
"github.com/rwxrob/bonzai/loop"
"github.com/rwxrob/bonzai/each"
)
// Cmd is a struct the easier to use and read when creating
@ -79,10 +79,10 @@ func (x *Cmd) Run() {
if cmd.Completer == nil {
list := comp.Standard(cmd, args...)
loop.Println(list)
each.Println(list)
Exit()
}
loop.Println(cmd.Completer(cmd, args...))
each.Println(cmd.Completer(cmd, args...))
Exit()
}

@ -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
},
}
*/

@ -6,8 +6,8 @@ package filt_test
import (
"fmt"
"github.com/rwxrob/bonzai/each"
"github.com/rwxrob/bonzai/filt"
"github.com/rwxrob/bonzai/loop"
)
func ExampleHasPrefix() {
@ -26,7 +26,7 @@ func ExampleBaseHasPrefix() {
"some/",
"some/blah",
}
loop.Println(filt.BaseHasPrefix(paths, "f"))
each.Println(filt.BaseHasPrefix(paths, "f"))
// Output:
// some/foo
// some/foo1

@ -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
}

@ -4,12 +4,12 @@ import (
"fmt"
"os"
"github.com/rwxrob/bonzai/loop"
"github.com/rwxrob/bonzai/each"
"github.com/rwxrob/bonzai/util"
)
func ExampleFiles() {
loop.Println(util.Files("testdata/files"))
each.Println(util.Files("testdata/files"))
// Output:
// testdata/files/bar
// testdata/files/blah
@ -22,7 +22,7 @@ func ExampleFiles() {
}
func ExampleFiles_spaces() {
loop.Println(util.Files("testdata/files/dir1"))
each.Println(util.Files("testdata/files/dir1"))
// Output:
// testdata/files/dir1/some\ thing
}
@ -30,7 +30,7 @@ func ExampleFiles_spaces() {
func ExampleFiles_empty() {
os.Chdir("testdata/files")
defer os.Chdir("../..")
loop.Println(util.Files(""))
each.Println(util.Files(""))
// Output:
// bar
// blah

Loading…
Cancel
Save