search

package
v0.0.0-...-8d9fac4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2024 License: CC-BY-SA-4.0, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SubCommand = cli2.SubCommand{
	Help: "search for given names",
	Command: func(args []string, procInout cli2.ProcInout) byte {
		strokesMap := kanji.LoadStrokes()
		strokesFunc := strokes.ByMap(strokesMap)
		yomiMap := kanji.LoadYomi()
		yomiFunc := yomi.ByCartesian(yomiMap)
		cm := loader.Intersection(loader.Load(strokesMap), loader.Load(yomiMap))

		opts, err := ParseOptions(args, procInout.Stdin, procInout.Stderr, cm, strokesFunc, yomiFunc)
		if err != nil {
			_, _ = fmt.Fprintf(procInout.Stderr, "failed to parse options: %s\n", err.Error())
			return 1
		}

		if opts.Help {
			return 0
		}

		genOpts := gen.Options{
			MinLength: opts.MinLength,
			MaxLength: opts.MaxLength,
		}

		if err := Main(
			opts.FamilyName,
			opts.GeneratorFunc,
			genOpts,
			opts.Filter,
			strokesFunc,
			printer.NewTSVPrinter(procInout.Stdout),
			sex.ByNameLists(sex.LoadMaleNames(), sex.LoadFemaleNames()),
		); err != nil {
			_, _ = fmt.Fprintf(procInout.Stderr, "failed to search: %s\n", err.Error())
			return 1
		}
		return 0
	},
}

Functions

func Main

func Main(familyName []rune, genFunc gen.GenerateFunc, genOpts gen.Options, filterFunc filter.Func, strokesFunc strokes.Func, printFunc printer.Func, sexFunc sex.Func) error

Types

type Options

type Options struct {
	Help          bool
	Filter        filter.Func
	FamilyName    []rune
	MinLength     int
	MaxLength     int
	GeneratorFunc gen.GenerateFunc
}

func ParseOptions

func ParseOptions(args []string, stdin io.Reader, stderr io.Writer, cm map[rune]struct{}, strokesFunc strokes.Func, yomiFunc yomi.Func) (*Options, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL