info

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: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SubCommand = cli.SubCommand{
	Help: "show information about a given name",
	Command: func(args []string, procInout cli.ProcInout) byte {
		strokesMap := kanji.LoadStrokes()
		strokesFunc := strokes.ByMap(strokesMap)
		yomiMap := kanji.LoadYomi()
		cm := loader.Intersection(loader.Load(strokesMap), loader.Load(yomiMap))

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

		if opts.Help {
			return 0
		}

		yomiString := string(opts.Yomi)
		printer.PrintTSVHeader(procInout.Stdout)

		evalResult, err := eval.Evaluate(opts.FamilyName, opts.GivenName, strokesFunc)
		if err != nil {
			_, _ = fmt.Fprintf(procInout.Stderr, "failed to evaluate: %s\n", err.Error())
			return 1
		}

		sexFunc := sex.ByNameLists(sex.LoadMaleNames(), sex.LoadFemaleNames())

		s, err := strokes.Sum(opts.GivenName, strokesFunc)
		if err != nil {
			_, _ = fmt.Fprintf(procInout.Stderr, "failed to sum strokes: %s\n", err.Error())
			return 1
		}

		target := filter.Target{
			Kanji:      opts.GivenName,
			Yomi:       opts.Yomi,
			YomiString: yomiString,
			Strokes:    s,
			Mora:       mora.Count(opts.Yomi),
			Sex:        sexFunc(yomiString),
			EvalResult: evalResult,
		}
		printer.PrintTSVRow(procInout.Stdout, target)
		return 0
	},
}

Functions

This section is empty.

Types

type Options

type Options struct {
	Help       bool
	FamilyName []rune
	GivenName  []rune
	Yomi       []rune
}

func ParseOptions

func ParseOptions(args []string, stderr io.Writer, cm map[rune]struct{}) (Options, error)

Jump to

Keyboard shortcuts

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