Skip to content
Myr

Fix option validation order

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 88e78c9 · Browse files · 1 file+52 added−39 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+52 added−39 removed

  • other:+52 added−39 removed

1 file+52 added−39 removed

modified:src/options.go+52 added-39 removed
2614 unmodified lines
2615 }2616 return nil2617}26182619func validateOptions(opts *Options) error {2620 if opts.Pointer != nil {2621 if err := validateSign(*opts.Pointer, "pointer"); err != nil {2622 return err2623 }2624 }26252626 if opts.Marker != nil {2627 if err := validateSign(*opts.Marker, "marker"); err != nil {2628 return err2629 }2630 }26312632 if !tui.IsLightRendererSupported() && opts.Height.size > 0 {2633 return errors.New("--height option is currently not supported on this platform")2634 }26352636 if opts.Scrollbar != nil {2637 runes := []rune(*opts.Scrollbar)2638 if len(runes) > 2 {2639 return errors.New("--scrollbar should be given one or two characters")2640 }2641 for _, r := range runes {2642 if uniseg.StringWidth(string(r)) != 1 {2643 return errors.New("scrollbar display width should be 1")2644 }2645 }2646 }26472648 if opts.Height.auto {2649 for _, s := range []sizeSpec{opts.Margin[0], opts.Margin[2]} {2650 if s.percent {2651 return errors.New("adaptive height is not compatible with top/bottom percent margin")2652 }2653 }2654 for _, s := range []sizeSpec{opts.Padding[0], opts.Padding[2]} {2655 if s.percent {2656 return errors.New("adaptive height is not compatible with top/bottom percent padding")2657 }2658 }2659 }26602661 return nil2662}26632664// This function can have side-effects and alter some global states.2665// So we run it on fzf.Run and not on ParseOptions.2666func postProcessOptions(opts *Options) error {2667 if opts.Ambidouble {
20 unmodified lines
2688 }2689 opts.Marker = &defaultMarker2690 }26912647 if err := validateSign(*opts.Pointer, "pointer"); err != nil {2648 return err2649 }26502651 if err := validateSign(*opts.Marker, "marker"); err != nil {2652 return err2653 }26542655 if !tui.IsLightRendererSupported() && opts.Height.size > 0 {2656 return errors.New("--height option is currently not supported on this platform")2657 }26582659 if opts.Scrollbar != nil {2660 runes := []rune(*opts.Scrollbar)2661 if len(runes) > 2 {2662 return errors.New("--scrollbar should be given one or two characters")2663 }2664 for _, r := range runes {2665 if uniseg.StringWidth(string(r)) != 1 {2666 return errors.New("scrollbar display width should be 1")2667 }2668 }2669 }26702692 // Default actions for CTRL-N / CTRL-P when --history is set2693 if opts.History != nil {2694 if _, prs := opts.Keymap[tui.CtrlP.AsEvent()]; !prs {2695 opts.Keymap[tui.CtrlP.AsEvent()] = toActions(actPrevHistory)
38 unmodified lines
2734 if _, prs := opts.Keymap[tui.DoubleClick.AsEvent()]; !prs {2735 opts.Keymap[tui.DoubleClick.AsEvent()] = opts.Keymap[tui.CtrlM.AsEvent()]2736 }27372717 if opts.Height.auto {2718 for _, s := range []sizeSpec{opts.Margin[0], opts.Margin[2]} {2719 if s.percent {2720 return errors.New("adaptive height is not compatible with top/bottom percent margin")2721 }2722 }2723 for _, s := range []sizeSpec{opts.Padding[0], opts.Padding[2]} {2724 if s.percent {2725 return errors.New("adaptive height is not compatible with top/bottom percent padding")2726 }2727 }2728 }27292738 // If we're not using extended search mode, --nth option becomes irrelevant2739 // if it contains the whole range2740 if !opts.Extended || len(opts.Nth) == 1 {2741 for _, r := range opts.Nth {
20 unmodified lines
2762 theme.Cursor = boldify(theme.Cursor)2763 theme.Spinner = boldify(theme.Spinner)2764 }27652766 if err := opts.initProfiling(); err != nil {2767 return errors.New("failed to start pprof profiles: " + err.Error())2768 }27692770 return processScheme(opts)2771}27722773// ParseOptions parses command-line options
35 unmodified lines
2809 if err := parseOptions(opts, args); err != nil {2810 return nil, err2811 }28122801 if err := opts.initProfiling(); err != nil {2802 return nil, errors.New("failed to start pprof profiles: " + err.Error())2813 // 4. Final validation of merged options2814 if err := validateOptions(opts); err != nil {2815 return nil, err2816 }28172818 return opts, nil2819}