MCPcopy
hub / github.com/livebud/bud / parse

Method parse

package/commander/subcommand.go:68–125  ·  view source on GitHub ↗
(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

66}
67
68func (c *Subcommand) parse(ctx context.Context, args []string) error {
69 // Set flags
70 c.setFlags()
71 // Parse the arguments
72 if err := c.fset.Parse(args); err != nil {
73 // Print usage if the developer used -h or --help
74 if errors.Is(err, flag.ErrHelp) {
75 return c.printUsage()
76 }
77 return err
78 }
79 // Verify that all the flags have been set or have default values
80 if err := verifyFlags(c.flags); err != nil {
81 return err
82 }
83 // Check if the first argument is a subcommand
84 if sub, ok := c.commands[c.fset.Arg(0)]; ok {
85 return sub.parse(ctx, c.fset.Args()[1:])
86 }
87 // Handle the remaining arguments
88 numArgs := len(c.args)
89 restArgs := c.fset.Args()
90loop:
91 for i, arg := range restArgs {
92 if i >= numArgs {
93 if c.restArgs == nil {
94 return fmt.Errorf("unexpected %s", arg)
95 }
96 // Loop over the remaining unset args, appending them to restArgs
97 for _, arg := range restArgs[i:] {
98 c.restArgs.value.Set(arg)
99 }
100 break loop
101 }
102 if err := c.args[i].value.Set(arg); err != nil {
103 return err
104 }
105 }
106 // Verify that all the args have been set or have default values
107 if err := verifyArgs(c.args); err != nil {
108 return err
109 }
110 // Print usage if there's no run function defined
111 if c.run == nil {
112 if len(restArgs) == 0 {
113 return c.printUsage()
114 }
115 return fmt.Errorf("unexpected %s", c.fset.Arg(0))
116 }
117 if err := c.run(ctx); err != nil {
118 // Support explicitly printing usage
119 if errors.Is(err, flag.ErrHelp) {
120 return c.printUsage()
121 }
122 return err
123 }
124 return nil
125}

Callers 9

ParseMethod · 0.80
compiler.jsFile · 0.80
parse3Function · 0.80
read_styleFunction · 0.80
decodeSourceMapFunction · 0.80
getPropsFunction · 0.80
HotClass · 0.80
ParseMethod · 0.80

Calls 10

setFlagsMethod · 0.95
printUsageMethod · 0.95
verifyFlagsFunction · 0.85
verifyArgsFunction · 0.85
IsMethod · 0.80
runMethod · 0.80
ArgMethod · 0.65
ArgsMethod · 0.65
SetMethod · 0.65
ParseMethod · 0.45

Tested by

no test coverage detected