formatting

This commit is contained in:
Arpad Ryszka 2025-09-01 04:10:35 +02:00
parent d7dfbd221f
commit 221de5c509
12 changed files with 363 additions and 135 deletions

View File

@ -20,7 +20,7 @@ func bindKeyVals(receiver reflect.Value, keyVals map[string][]string) bool {
func bindOptions(receiver reflect.Value, shortForms []string, o []option) bool { func bindOptions(receiver reflect.Value, shortForms []string, o []option) bool {
ms := make(map[string]string) ms := make(map[string]string)
for i := 0; i < len(shortForms); i += 2 { for i := 0; i < len(shortForms); i += 2 {
ms[shortForms[i]] = shortForms[i + 1] ms[shortForms[i]] = shortForms[i+1]
} }
v := make(map[string][]any) v := make(map[string][]any)

View File

@ -1,11 +1,11 @@
package wand package wand
import ( import (
"code.squareroundforest.org/arpio/bind"
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"regexp" "regexp"
"code.squareroundforest.org/arpio/bind"
) )
var commandNameExpression = regexp.MustCompile("^[a-zA-Z_][a-zA-Z_0-9]*$") var commandNameExpression = regexp.MustCompile("^[a-zA-Z_][a-zA-Z_0-9]*$")
@ -224,13 +224,13 @@ func validateShortFormsTree(cmd Cmd) (map[string]string, map[string]string, erro
} }
} }
if len(cmd.shortForms) % 2 != 0 { if len(cmd.shortForms)%2 != 0 {
return nil, nil, fmt.Errorf("unassigned short form: %s", cmd.shortForms[len(cmd.shortForms) - 1]) return nil, nil, fmt.Errorf("unassigned short form: %s", cmd.shortForms[len(cmd.shortForms)-1])
} }
mf := mapFields(cmd.impl) mf := mapFields(cmd.impl)
for i := 0; i < len(cmd.shortForms); i += 2 { for i := 0; i < len(cmd.shortForms); i += 2 {
s, l := cmd.shortForms[i], cmd.shortForms[i + 1] s, l := cmd.shortForms[i], cmd.shortForms[i+1]
r := []rune(s) r := []rune(s)
if len(r) != 1 || r[0] < 'a' || r[0] > 'z' { if len(r) != 1 || r[0] < 'a' || r[0] > 'z' {
return nil, nil, fmt.Errorf("invalid short form: %s", s) return nil, nil, fmt.Errorf("invalid short form: %s", s)

View File

@ -1,11 +1,11 @@
package wand package wand
import ( import (
"code.squareroundforest.org/arpio/bind"
"slices" "slices"
"strconv" "strconv"
"strings" "strings"
"unicode" "unicode"
"code.squareroundforest.org/arpio/bind"
) )
type value struct { type value struct {
@ -281,7 +281,7 @@ func hasHelpOption(cmd Cmd, o []option) bool {
sf := make(map[string]string) sf := make(map[string]string)
for i := 0; i < len(cmd.shortForms); i += 2 { for i := 0; i < len(cmd.shortForms); i += 2 {
sf[cmd.shortForms[i]] = cmd.shortForms[i + 1] sf[cmd.shortForms[i]] = cmd.shortForms[i+1]
} }
for _, oi := range o { for _, oi := range o {

View File

@ -2,30 +2,31 @@
Generated with https://code.squareroundforest.org/arpio/docreflect Generated with https://code.squareroundforest.org/arpio/docreflect
*/ */
package wand package wand
import "code.squareroundforest.org/arpio/docreflect" import "code.squareroundforest.org/arpio/docreflect"
func init() { func init() {
docreflect.Register("code.squareroundforest.org/arpio/wand/tools", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Docreflect", "\nfunc(out, packageName, gopaths)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Docreflect", "\nfunc(out, packageName, gopaths)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Exec", "\nfunc(o, stdin, args)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Exec", "\nfunc(o, stdin, args)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.CacheDir", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.CacheDir", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.ClearCache", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.ClearCache", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.Import", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.Import", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.InlineImport", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.InlineImport", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.NoCache", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.NoCache", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Man", "\nfunc(out, commandDir)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Man", "\nfunc(out, commandDir)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Markdown", "\nfunc(out, o, commandDir)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Markdown", "\nfunc(out, o, commandDir)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.MarkdownOptions", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.MarkdownOptions", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.MarkdownOptions.Level", "") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.MarkdownOptions.Level", "")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.commandReader", "\nfunc(in)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.commandReader", "\nfunc(in)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execCommandDir", "\nfunc(out, commandDir, env)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execCommandDir", "\nfunc(out, commandDir, env)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execInternal", "\nfunc(command, args)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execInternal", "\nfunc(command, args)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execTransparent", "\nfunc(command, args)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execTransparent", "\nfunc(command, args)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execWand", "\nfunc(o, args)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execWand", "\nfunc(o, args)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execc", "\nfunc(stdin, stdout, stderr, command, args, env)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execc", "\nfunc(stdin, stdout, stderr, command, args, env)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.hash", "\nfunc(expression, imports, inlineImports)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.hash", "\nfunc(expression, imports, inlineImports)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.printGoFile", "\nfunc(fn, expression, imports, inlineImports)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.printGoFile", "\nfunc(fn, expression, imports, inlineImports)")
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.readExec", "\nfunc(o, stdin)") docreflect.Register("code.squareroundforest.org/arpio/wand/tools.readExec", "\nfunc(o, stdin)")
} }

View File

@ -1,8 +1,8 @@
package wand package wand
import ( import (
"code.squareroundforest.org/arpio/docreflect"
"code.squareroundforest.org/arpio/bind" "code.squareroundforest.org/arpio/bind"
"code.squareroundforest.org/arpio/docreflect"
"fmt" "fmt"
"io" "io"
"reflect" "reflect"

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,9 @@
package wand package wand
import ( import (
"code.squareroundforest.org/arpio/bind"
"fmt" "fmt"
"reflect" "reflect"
"code.squareroundforest.org/arpio/bind"
) )
func validateKeyValues(cmd Cmd, keyValues map[string][]string, originalNames map[string]string) error { func validateKeyValues(cmd Cmd, keyValues map[string][]string, originalNames map[string]string) error {

View File

@ -1,11 +1,11 @@
package wand package wand
import ( import (
"reflect"
"code.squareroundforest.org/arpio/bind" "code.squareroundforest.org/arpio/bind"
"io" "io"
"time" "reflect"
"strings" "strings"
"time"
) )
func filter[T any](list []T, predicate func(T) bool) []T { func filter[T any](list []T, predicate func(T) bool) []T {
@ -297,7 +297,7 @@ func bindable(t reflect.Type) bool {
func scalarTypeString(t bind.Scalar) string { func scalarTypeString(t bind.Scalar) string {
r := reflect.TypeOf(t) r := reflect.TypeOf(t)
p := strings.Split(r.Name(), ".") p := strings.Split(r.Name(), ".")
n := p[len(p) - 1] n := p[len(p)-1]
n = strings.ToLower(n) n = strings.ToLower(n)
return n return n
} }

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"code.squareroundforest.org/arpio/wand/tools"
"log" "log"
"os" "os"
"code.squareroundforest.org/arpio/wand/tools"
) )
func main() { func main() {

View File

@ -1,11 +1,11 @@
package tools package tools
import ( import (
"io"
"strings"
"os/exec"
"os"
"bytes" "bytes"
"io"
"os"
"os/exec"
"strings"
) )
func execc(stdin io.Reader, stdout, stderr io.Writer, command string, args []string, env []string) error { func execc(stdin io.Reader, stdout, stderr io.Writer, command string, args []string, env []string) error {

View File

@ -1,33 +1,33 @@
package tools package tools
import ( import (
"io"
"bufio" "bufio"
"errors"
"fmt"
"unicode"
"hash/fnv"
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"strings" "errors"
"fmt"
"hash/fnv"
"io"
"os" "os"
"sort"
"path" "path"
"sort"
"strings"
"unicode"
) )
type ExecOptions struct { type ExecOptions struct {
NoCache bool NoCache bool
ClearCache bool ClearCache bool
CacheDir string CacheDir string
Import []string Import []string
InlineImport []string InlineImport []string
} }
func commandReader(in io.Reader) func() ([]string, error) { func commandReader(in io.Reader) func() ([]string, error) {
var ( var (
yieldErr error yieldErr error
currentArg []rune currentArg []rune
args []string args []string
escapeOne, escapePartial, escapeFull bool escapeOne, escapePartial, escapeFull bool
) )

View File

@ -2,8 +2,8 @@ package tools
import ( import (
"code.squareroundforest.org/arpio/docreflect/generate" "code.squareroundforest.org/arpio/docreflect/generate"
"io"
"fmt" "fmt"
"io"
) )
type MarkdownOptions struct { type MarkdownOptions struct {