MCPcopy Create free account
hub / github.com/diillson/chatcli / parseTreeArgs

Function parseTreeArgs

cli/plugins/builtin_tree.go:128–174  ·  view source on GitHub ↗

parseTreeArgs supports both flat JSON and the @coder envelope shape. Empty input is valid — @tree defaults to the current directory.

(args []string)

Source from the content-addressed store, hash-verified

126// parseTreeArgs supports both flat JSON and the @coder envelope shape.
127// Empty input is valid — @tree defaults to the current directory.
128func parseTreeArgs(args []string) (treeArgs, error) {
129 var out treeArgs
130 if len(args) == 0 {
131 return out, nil
132 }
133 first := strings.TrimSpace(args[0])
134 if strings.HasPrefix(first, "{") {
135 var raw map[string]json.RawMessage
136 if err := json.Unmarshal([]byte(first), &raw); err != nil {
137 return out, fmt.Errorf("@tree: malformed JSON args: %w", err)
138 }
139 if inner, ok := raw["args"]; ok {
140 var innerMap map[string]json.RawMessage
141 if jsonErr := json.Unmarshal(inner, &innerMap); jsonErr == nil {
142 raw = innerMap
143 }
144 }
145 out.Dir = jsonString(raw, "dir", "path", "directory")
146 out.Depth = jsonInt(raw, "depth", "maxDepth")
147 out.Exclude = jsonString(raw, "exclude", "skip")
148 return out, nil
149 }
150 for i := 0; i < len(args); i++ {
151 switch args[i] {
152 case "--dir":
153 if i+1 < len(args) {
154 out.Dir = args[i+1]
155 i++
156 }
157 case "--depth":
158 if i+1 < len(args) {
159 out.Depth, _ = strconv.Atoi(args[i+1])
160 i++
161 }
162 case "--exclude":
163 if i+1 < len(args) {
164 out.Exclude = args[i+1]
165 i++
166 }
167 default:
168 if out.Dir == "" && !strings.HasPrefix(args[i], "-") {
169 out.Dir = args[i]
170 }
171 }
172 }
173 return out, nil
174}
175
176// buildTreeArgv reconstructs the engine.handleTree argv form. We
177// expose intuitive names to the LLM (depth/exclude) but the engine

Callers 3

DescribeCallMethod · 0.85
ExecuteWithStreamMethod · 0.85

Calls 3

jsonStringFunction · 0.85
jsonIntFunction · 0.85
ErrorfMethod · 0.80

Tested by 1