MCPcopy
hub / github.com/spf13/cobra / TestFind

Function TestFind

command_test.go:2793–2880  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2791}
2792
2793func TestFind(t *testing.T) {
2794 var foo, bar string
2795 root := &Command{
2796 Use: "root",
2797 }
2798 root.PersistentFlags().StringVarP(&foo, "foo", "f", "", "")
2799 root.PersistentFlags().StringVarP(&bar, "bar", "b", "something", "")
2800
2801 child := &Command{
2802 Use: "child",
2803 }
2804 root.AddCommand(child)
2805
2806 testCases := []struct {
2807 args []string
2808 expectedFoundArgs []string
2809 }{
2810 {
2811 []string{"child"},
2812 []string{},
2813 },
2814 {
2815 []string{"child", "child"},
2816 []string{"child"},
2817 },
2818 {
2819 []string{"child", "foo", "child", "bar", "child", "baz", "child"},
2820 []string{"foo", "child", "bar", "child", "baz", "child"},
2821 },
2822 {
2823 []string{"-f", "child", "child"},
2824 []string{"-f", "child"},
2825 },
2826 {
2827 []string{"child", "-f", "child"},
2828 []string{"-f", "child"},
2829 },
2830 {
2831 []string{"-b", "child", "child"},
2832 []string{"-b", "child"},
2833 },
2834 {
2835 []string{"child", "-b", "child"},
2836 []string{"-b", "child"},
2837 },
2838 {
2839 []string{"child", "-b"},
2840 []string{"-b"},
2841 },
2842 {
2843 []string{"-b", "-f", "child", "child"},
2844 []string{"-b", "-f", "child"},
2845 },
2846 {
2847 []string{"-f", "child", "-b", "something", "child"},
2848 []string{"-f", "child", "-b", "something"},
2849 },
2850 {

Callers

nothing calls this directly

Calls 3

PersistentFlagsMethod · 0.95
AddCommandMethod · 0.95
FindMethod · 0.95

Tested by

no test coverage detected