diff --git a/util/exec.go b/exec.go similarity index 71% rename from util/exec.go rename to exec.go index acf1272..6b2d43b 100644 --- a/util/exec.go +++ b/exec.go @@ -1,20 +1,7 @@ -/* -Copyright 2021 Robert S. Muhlestein. +// Copyright 2022 Robert S. Muhlestein. +// SPDX-License-Identifier: Apache-2.0 -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util +package bonzai import ( "fmt" diff --git a/util/exec_test.go b/exec_test.go similarity index 65% rename from util/exec_test.go rename to exec_test.go index 95708d6..26422fe 100644 --- a/util/exec_test.go +++ b/exec_test.go @@ -1,20 +1,7 @@ -/* -Copyright 2021 Robert S. Muhlestein. +// Copyright 2022 Robert S. Muhlestein. +// SPDX-License-Identifier: Apache-2.0 -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util +package bonzai import ( "os" diff --git a/util/update.go b/update.go similarity index 98% rename from util/update.go rename to update.go index 15a6385..fb9ee92 100644 --- a/util/update.go +++ b/update.go @@ -1,4 +1,4 @@ -package util +package bonzai import ( "log" diff --git a/util/update_test.go b/update_test.go similarity index 69% rename from util/update_test.go rename to update_test.go index c0ed024..9752d10 100644 --- a/util/update_test.go +++ b/update_test.go @@ -1,11 +1,11 @@ -package util_test +package bonzai_test import ( "fmt" "net/http" ht "net/http/httptest" - "github.com/rwxrob/bonzai/util" + "github.com/rwxrob/bonzai" ) func ExampleCompareUpdated() { @@ -31,10 +31,10 @@ func ExampleCompareUpdated() { same := ht.NewServer(handler) defer same.Close() - fmt.Println(util.CompareUpdated(20220322080542, older.URL)) - fmt.Println(util.CompareUpdated(20220322080542, newer.URL)) - fmt.Println(util.CompareUpdated(20220322080542, same.URL)) - fmt.Println(util.CompareUpdated(20220322080542, "foobar")) + fmt.Println(bonzai.CompareUpdated(20220322080542, older.URL)) + fmt.Println(bonzai.CompareUpdated(20220322080542, newer.URL)) + fmt.Println(bonzai.CompareUpdated(20220322080542, same.URL)) + fmt.Println(bonzai.CompareUpdated(20220322080542, "foobar")) // Output: // -1 @@ -66,10 +66,10 @@ func ExampleCompareVersions() { same := ht.NewServer(handler) defer same.Close() - fmt.Println(util.CompareVersions(`v0.0.2`, older.URL)) - fmt.Println(util.CompareVersions(`v0.0.2`, newer.URL)) - fmt.Println(util.CompareVersions(`v0.0.2`, same.URL)) - fmt.Println(util.CompareVersions(`v0.0.2`, "foobar")) + fmt.Println(bonzai.CompareVersions(`v0.0.2`, older.URL)) + fmt.Println(bonzai.CompareVersions(`v0.0.2`, newer.URL)) + fmt.Println(bonzai.CompareVersions(`v0.0.2`, same.URL)) + fmt.Println(bonzai.CompareVersions(`v0.0.2`, "foobar")) // Output: // 1 diff --git a/util/files.go b/util/files.go deleted file mode 100644 index 6bc76f0..0000000 --- a/util/files.go +++ /dev/null @@ -1,34 +0,0 @@ -package util - -import ( - "os" - - "github.com/rwxrob/fn/maps" -) - -// Files returns a slice of strings matching the names of the files -// within the given directory adding a slash to the end of any -// directories and escaping any spaces by adding backslash. Note that -// this (and all functions of the bonzai package) assume forward slash -// path separators because no path argument should ever be passed to any -// bonzai command or high-level library that does not use forward slash -// paths. Commands should always use the comp.Files completer instead of -// host shell completion. -func Files(dir string) []string { - if dir == "" { - dir = "." - } - files := []string{} - entries, err := os.ReadDir(dir) - if err != nil { - return files - } - names := maps.MarkDirs(entries) - if dir == "." { - return names - } - if dir[len(dir)-1] != '/' { - dir += "/" - } - return maps.EscSpace(maps.Prefix(names, dir)) -} diff --git a/util/files_test.go b/util/files_test.go deleted file mode 100644 index c0d5148..0000000 --- a/util/files_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package util_test - -import ( - "fmt" - "os" - - "github.com/rwxrob/bonzai/util" - "github.com/rwxrob/fn/each" -) - -func ExampleFiles() { - each.Println(util.Files("testdata/files")) - // Output: - // testdata/files/bar - // testdata/files/blah - // testdata/files/dir1/ - // testdata/files/foo - // testdata/files/other - // testdata/files/some -} - -func ExampleFiles_spaces() { - each.Println(util.Files("testdata/files/dir1")) - // Output: - // testdata/files/dir1/some\ thing -} - -func ExampleFiles_empty() { - os.Chdir("testdata/files") - defer os.Chdir("../..") - each.Println(util.Files("")) - // Output: - // bar - // blah - // dir1/ - // foo - // other - // some -} - -func ExampleFiles_not_Directory() { - fmt.Println(util.Files("none")) - // Output: - // [] -} diff --git a/util/func.go b/util/func.go deleted file mode 100644 index abf89cc..0000000 --- a/util/func.go +++ /dev/null @@ -1,17 +0,0 @@ -package util - -import ( - "reflect" - "runtime" - "strings" -) - -// FuncName makes a best effort attempt to return the string name of the -// passed function. Anonymous functions are named "funcN" where N is the -// order of appearance within the current scope. Note that this function -// will panic if not passed a function. -func FuncName(i any) string { - p := runtime.FuncForPC(reflect.ValueOf(i).Pointer()) - n := strings.Split(p.Name(), `.`) - return n[len(n)-1] -} diff --git a/util/func_test.go b/util/func_test.go deleted file mode 100644 index f5beca8..0000000 --- a/util/func_test.go +++ /dev/null @@ -1 +0,0 @@ -package util_test diff --git a/util/stack.go b/util/stack.go deleted file mode 100644 index f4a31f8..0000000 --- a/util/stack.go +++ /dev/null @@ -1,45 +0,0 @@ -package util - -type stacked struct { - val any - left *stacked - right *stacked -} - -// Stack implements a simple stack data structure using a linked list. -type Stack struct { - first *stacked - last *stacked -} - -// Push will add an item of any type to the stack in front of the -// others. -func (s *Stack) Push(it any) { - n := new(stacked) - n.val = it - if s.first == nil { - s.first = n - s.last = n - return - } - s.last.right = n - n.left = s.last - s.last = n -} - -// Pop will remove the most recently added item and return it. -func (s *Stack) Pop() any { - if s.last == nil { - return nil - } - popped := s.last.val - s.last = s.last.left - return popped -} - -func (s *Stack) Peek() any { - if s.last == nil { - return nil - } - return s.last.val -} diff --git a/util/stack_test.go b/util/stack_test.go deleted file mode 100644 index 38065ee..0000000 --- a/util/stack_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package util_test - -import ( - "fmt" - - "github.com/rwxrob/bonzai/util" -) - -func ExampleStack() { - s := new(util.Stack) - s.Push("some") - s.Push("another") - fmt.Println(s.Peek()) - fmt.Println(s.Pop()) - fmt.Println(s.Peek()) - s.Push(1) - fmt.Println(s.Peek()) - s.Pop() - s.Pop() - fmt.Println(s.Peek()) - // Output: - // another - // another - // some - // 1 - // -} diff --git a/util/strings.go b/util/strings.go deleted file mode 100644 index 3c35cb5..0000000 --- a/util/strings.go +++ /dev/null @@ -1,19 +0,0 @@ -package util - -import ( - "bufio" - "fmt" - "strings" -) - -// Lines transforms the input into a string and then divides that string -// up into lines (\r?\n) suitable for functional map operations. -func Lines[T any](in T) []string { - buf := fmt.Sprintf("%v", in) - lines := []string{} - scan := bufio.NewScanner(strings.NewReader(buf)) - for scan.Scan() { - lines = append(lines, scan.Text()) - } - return lines -} diff --git a/util/strings_test.go b/util/strings_test.go deleted file mode 100644 index f5beca8..0000000 --- a/util/strings_test.go +++ /dev/null @@ -1 +0,0 @@ -package util_test diff --git a/util/testdata/files/bar b/util/testdata/files/bar deleted file mode 100644 index e69de29..0000000 diff --git a/util/testdata/files/blah b/util/testdata/files/blah deleted file mode 100644 index e69de29..0000000 diff --git a/util/testdata/files/dir1/some thing b/util/testdata/files/dir1/some thing deleted file mode 100644 index e69de29..0000000 diff --git a/util/testdata/files/foo b/util/testdata/files/foo deleted file mode 100644 index e69de29..0000000 diff --git a/util/testdata/files/other b/util/testdata/files/other deleted file mode 100644 index e69de29..0000000 diff --git a/util/testdata/files/some b/util/testdata/files/some deleted file mode 100644 index e69de29..0000000