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

Method handleCreate

cli/context_handler.go:101–211  ·  view source on GitHub ↗

handleCreate cria um novo contexto

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

99
100// handleCreate cria um novo contexto
101func (h *ContextHandler) handleCreate(ctx context.Context, args []string) error {
102 if len(args) < 2 {
103 return fmt.Errorf("%s", i18n.T("context.create.usage"))
104 }
105
106 // Parser de argumentos melhorado
107 var name, description, modeStr string
108 var paths []string
109 var tags []string
110
111 // Primeiro argumento é o nome
112 name = args[0]
113
114 var force bool
115 // Processar flags e paths
116 i := 1
117 for i < len(args) {
118 arg := args[i]
119
120 switch {
121 case arg == "--mode" || arg == "-m":
122 if i+1 >= len(args) {
123 return fmt.Errorf("%s", i18n.T("context.create.error.mode_required"))
124 }
125 i++ // Avançar para o valor
126 modeStr = args[i]
127 i++ // Avançar para o próximo argumento
128
129 case arg == "--description" || arg == "--desc" || arg == "-d":
130 if i+1 >= len(args) {
131 return fmt.Errorf("%s", i18n.T("context.create.error.description_required"))
132 }
133 i++ // Avançar para o valor
134 description = args[i]
135 i++ // Avançar para o próximo argumento
136
137 case arg == "--tags" || arg == "-t":
138 if i+1 >= len(args) {
139 return fmt.Errorf("%s", i18n.T("context.create.error.tags_required"))
140 }
141 i++ // Avançar para o valor
142 tags = strings.Split(args[i], ",")
143 i++ // Avançar para o próximo argumento
144
145 case arg == "--force" || arg == "-f":
146 force = true
147 i++
148
149 case strings.HasPrefix(arg, "--") || strings.HasPrefix(arg, "-"):
150 // Flag desconhecida
151 return fmt.Errorf("%s", i18n.T("context.io.error.unknown_flag", arg))
152
153 default:
154 // É um path
155 paths = append(paths, arg)
156 i++
157 }
158 }

Callers 1

HandleContextCommandMethod · 0.95

Calls 6

printContextInfoMethod · 0.95
TFunction · 0.92
ProcessingModeTypeAlias · 0.92
colorizeFunction · 0.85
ErrorfMethod · 0.80
CreateContextMethod · 0.80

Tested by

no test coverage detected