Skip to content

Commit 0333877

Browse files
committed
chore: remove trailing whitespace in client_config.go and client.go
- Cleaned up trailing whitespace in client_config.go and client.go files to enhance code readability and maintain consistency across the codebase.
1 parent 558e1cb commit 0333877

2 files changed

Lines changed: 53 additions & 54 deletions

File tree

cmd/forge/plugins/client.go

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ func (p *ClientPlugin) Commands() []cli.Command {
5151
cli.WithFlag(cli.NewStringFlag("package", "p", "Package/module name", "")),
5252
cli.WithFlag(cli.NewStringFlag("base-url", "b", "API base URL", "")),
5353
cli.WithFlag(cli.NewStringFlag("module", "m", "Go module path (for Go only)", "")),
54-
54+
5555
// Authentication and streaming (optional, defaults from config)
5656
cli.WithFlag(cli.NewBoolFlag("auth", "", "Include authentication", true)),
5757
cli.WithFlag(cli.NewBoolFlag("no-auth", "", "Disable authentication", false)),
5858
cli.WithFlag(cli.NewBoolFlag("streaming", "", "Include streaming (WebSocket/SSE)", true)),
5959
cli.WithFlag(cli.NewBoolFlag("no-streaming", "", "Disable streaming", false)),
60-
60+
6161
// Streaming features
6262
cli.WithFlag(cli.NewBoolFlag("reconnection", "", "Enable reconnection", true)),
6363
cli.WithFlag(cli.NewBoolFlag("heartbeat", "", "Enable heartbeat", true)),
6464
cli.WithFlag(cli.NewBoolFlag("state-management", "", "Enable state management", true)),
65-
65+
6666
// Enhanced features
6767
cli.WithFlag(cli.NewBoolFlag("use-fetch", "", "Use native fetch instead of axios (TypeScript)", true)),
6868
cli.WithFlag(cli.NewBoolFlag("dual-package", "", "Generate dual ESM+CJS package (TypeScript)", true)),
@@ -96,20 +96,20 @@ func (p *ClientPlugin) generateClient(ctx cli.CommandContext) error {
9696
// Try to load .forge-client.yml config
9797
var clientConfig *ClientConfig
9898
var err error
99-
99+
100100
workDir, _ := os.Getwd()
101101
if p.config != nil {
102102
workDir = p.config.RootDir
103103
}
104-
104+
105105
clientConfig, err = LoadClientConfig(workDir)
106106
if err != nil {
107107
// Config not found, use defaults
108108
clientConfig = DefaultClientConfig()
109109
} else {
110110
ctx.Info("Using .forge-client.yml configuration")
111111
}
112-
112+
113113
// Get flags (command-line overrides config)
114114
fromSpec := ctx.String("from-spec")
115115
fromURL := ctx.String("from-url")
@@ -118,7 +118,7 @@ func (p *ClientPlugin) generateClient(ctx cli.CommandContext) error {
118118
packageName := ctx.String("package")
119119
baseURL := ctx.String("base-url")
120120
module := ctx.String("module")
121-
121+
122122
// Use config defaults if flags not provided
123123
if language == "" {
124124
language = clientConfig.Defaults.Language
@@ -135,27 +135,27 @@ func (p *ClientPlugin) generateClient(ctx cli.CommandContext) error {
135135
if module == "" {
136136
module = clientConfig.Defaults.Module
137137
}
138-
138+
139139
// Authentication and streaming (handle both positive and negative flags)
140140
includeAuth := clientConfig.Defaults.Auth
141141
if ctx.Bool("no-auth") {
142142
includeAuth = false
143143
} else if ctx.Bool("auth") {
144144
includeAuth = true
145145
}
146-
146+
147147
includeStreaming := clientConfig.Defaults.Streaming
148148
if ctx.Bool("no-streaming") {
149149
includeStreaming = false
150150
} else if ctx.Bool("streaming") {
151151
includeStreaming = true
152152
}
153-
153+
154154
// Streaming features (use config defaults)
155155
reconnection := clientConfig.Defaults.Reconnection
156156
heartbeat := clientConfig.Defaults.Heartbeat
157157
stateManagement := clientConfig.Defaults.StateManagement
158-
158+
159159
// Enhanced features (use config defaults)
160160
useFetch := clientConfig.Defaults.UseFetch
161161
dualPackage := clientConfig.Defaults.DualPackage
@@ -165,92 +165,92 @@ func (p *ClientPlugin) generateClient(ctx cli.CommandContext) error {
165165
errorTaxonomy := clientConfig.Defaults.ErrorTaxonomy
166166
interceptors := clientConfig.Defaults.Interceptors
167167
pagination := clientConfig.Defaults.Pagination
168-
168+
169169
// Determine spec source
170170
var specPath string
171171
var specData []byte
172-
172+
173173
switch {
174174
case fromSpec != "":
175175
// Use provided spec file
176176
specPath = fromSpec
177177
ctx.Info(fmt.Sprintf("Using spec file: %s", specPath))
178-
178+
179179
case fromURL != "":
180180
// Fetch from URL
181181
ctx.Info(fmt.Sprintf("Fetching spec from: %s", fromURL))
182182
spinner := ctx.Spinner("Downloading specification...")
183-
183+
184184
specData, err = fetchSpecFromURL(fromURL, 0)
185185
if err != nil {
186186
spinner.Stop(cli.Red("✗ Failed"))
187187
return fmt.Errorf("fetch spec from URL: %w", err)
188188
}
189-
189+
190190
spinner.Stop(cli.Green("✓ Spec downloaded"))
191-
191+
192192
// Save to temp file
193193
tmpFile, err := os.CreateTemp("", "forge-client-spec-*.json")
194194
if err != nil {
195195
return fmt.Errorf("create temp file: %w", err)
196196
}
197197
defer os.Remove(tmpFile.Name())
198-
198+
199199
if _, err := tmpFile.Write(specData); err != nil {
200200
return fmt.Errorf("write temp file: %w", err)
201201
}
202202
tmpFile.Close()
203-
203+
204204
specPath = tmpFile.Name()
205-
205+
206206
case clientConfig.Source.Type == "url":
207207
// Use URL from config
208208
if clientConfig.Source.URL == "" {
209209
return cli.NewError("source.url is empty in .forge-client.yml", cli.ExitUsageError)
210210
}
211-
211+
212212
ctx.Info(fmt.Sprintf("Fetching spec from: %s (configured)", clientConfig.Source.URL))
213213
spinner := ctx.Spinner("Downloading specification...")
214-
214+
215215
specData, err = fetchSpecFromURL(clientConfig.Source.URL, 0)
216216
if err != nil {
217217
spinner.Stop(cli.Red("✗ Failed"))
218218
return fmt.Errorf("fetch spec from URL: %w", err)
219219
}
220-
220+
221221
spinner.Stop(cli.Green("✓ Spec downloaded"))
222-
222+
223223
// Save to temp file
224224
tmpFile, err := os.CreateTemp("", "forge-client-spec-*.json")
225225
if err != nil {
226226
return fmt.Errorf("create temp file: %w", err)
227227
}
228228
defer os.Remove(tmpFile.Name())
229-
229+
230230
if _, err := tmpFile.Write(specData); err != nil {
231231
return fmt.Errorf("write temp file: %w", err)
232232
}
233233
tmpFile.Close()
234-
234+
235235
specPath = tmpFile.Name()
236-
236+
237237
case clientConfig.Source.Type == "file":
238238
// Use file from config
239239
if clientConfig.Source.Path == "" {
240240
return cli.NewError("source.path is empty in .forge-client.yml", cli.ExitUsageError)
241241
}
242-
242+
243243
specPath = clientConfig.Source.Path
244244
if !filepath.IsAbs(specPath) {
245245
specPath = filepath.Join(workDir, specPath)
246246
}
247-
247+
248248
ctx.Info(fmt.Sprintf("Using spec file: %s (configured)", specPath))
249-
249+
250250
case clientConfig.Source.Type == "auto" || clientConfig.Source.Type == "":
251251
// Auto-discover spec file
252252
ctx.Info("Auto-discovering spec file...")
253-
253+
254254
specPath, err = autoDiscoverSpec(workDir, clientConfig.Source.AutoDiscoverPaths)
255255
if err != nil {
256256
ctx.Warning("No spec file found. Options:")
@@ -264,13 +264,13 @@ func (p *ClientPlugin) generateClient(ctx cli.CommandContext) error {
264264
}
265265
return cli.NewError("no spec file found", cli.ExitUsageError)
266266
}
267-
267+
268268
ctx.Success(fmt.Sprintf("Found spec: %s", specPath))
269-
269+
270270
default:
271271
return cli.NewError("unknown source type in config: "+clientConfig.Source.Type, cli.ExitUsageError)
272272
}
273-
273+
274274
// Validate spec path exists
275275
if specPath == "" {
276276
return cli.NewError("no spec source provided", cli.ExitUsageError)
@@ -397,54 +397,54 @@ func (p *ClientPlugin) listEndpoints(ctx cli.CommandContext) error {
397397
// Determine spec source (similar to generateClient)
398398
var specPath string
399399
var err error
400-
400+
401401
workDir, _ := os.Getwd()
402402
if p.config != nil {
403403
workDir = p.config.RootDir
404404
}
405-
405+
406406
switch {
407407
case fromSpec != "":
408408
specPath = fromSpec
409-
409+
410410
case fromURL != "":
411411
// Fetch from URL
412412
ctx.Info(fmt.Sprintf("Fetching spec from: %s", fromURL))
413-
413+
414414
specData, err := fetchSpecFromURL(fromURL, 0)
415415
if err != nil {
416416
return fmt.Errorf("fetch spec from URL: %w", err)
417417
}
418-
418+
419419
// Save to temp file
420420
tmpFile, err := os.CreateTemp("", "forge-client-spec-*.json")
421421
if err != nil {
422422
return fmt.Errorf("create temp file: %w", err)
423423
}
424424
defer os.Remove(tmpFile.Name())
425-
425+
426426
if _, err := tmpFile.Write(specData); err != nil {
427427
return fmt.Errorf("write temp file: %w", err)
428428
}
429429
tmpFile.Close()
430-
430+
431431
specPath = tmpFile.Name()
432-
432+
433433
default:
434434
// Try auto-discovery
435435
clientConfig, err := LoadClientConfig(workDir)
436436
if err != nil {
437437
clientConfig = DefaultClientConfig()
438438
}
439-
439+
440440
specPath, err = autoDiscoverSpec(workDir, clientConfig.Source.AutoDiscoverPaths)
441441
if err != nil {
442442
ctx.Warning("No spec file found. Provide one with:")
443443
ctx.Println(" --from-spec ./openapi.yaml")
444444
ctx.Println(" --from-url http://localhost:8080/openapi.json")
445445
return cli.NewError("no spec source provided", cli.ExitUsageError)
446446
}
447-
447+
448448
ctx.Info(fmt.Sprintf("Using spec: %s", specPath))
449449
}
450450

@@ -542,7 +542,7 @@ func (p *ClientPlugin) listEndpoints(ctx cli.CommandContext) error {
542542
func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
543543
ctx.Info("Initializing client generation configuration...")
544544
ctx.Println("")
545-
545+
546546
// Prompt for source type
547547
sourceType, err := ctx.Select("How do you want to provide the API specification?", []string{
548548
"auto - Auto-discover from common paths",
@@ -552,13 +552,13 @@ func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
552552
if err != nil {
553553
return err
554554
}
555-
555+
556556
// Extract just the type (before the dash)
557557
sourceType = sourceType[:4]
558-
558+
559559
config := DefaultClientConfig()
560560
config.Source.Type = sourceType
561-
561+
562562
switch sourceType {
563563
case "file":
564564
path, err := ctx.Prompt("Spec file path [./openapi.yaml]:")
@@ -570,7 +570,7 @@ func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
570570
}
571571
config.Source.Path = path
572572
config.Source.AutoDiscoverPaths = nil
573-
573+
574574
case "url ":
575575
url, err := ctx.Prompt("Spec URL [http://localhost:8080/openapi.json]:")
576576
if err != nil {
@@ -581,15 +581,15 @@ func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
581581
}
582582
config.Source.URL = url
583583
config.Source.AutoDiscoverPaths = nil
584-
584+
585585
case "auto":
586586
// Keep default auto-discover paths
587587
ctx.Info("Will auto-discover from common paths:")
588588
for _, path := range config.Source.AutoDiscoverPaths {
589589
ctx.Println(" - " + path)
590590
}
591591
}
592-
592+
593593
ctx.Println("")
594594

595595
// Prompt for language
@@ -625,7 +625,7 @@ func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
625625
return err
626626
}
627627
config.Defaults.BaseURL = baseURL
628-
628+
629629
// For Go, ask for module
630630
if language == "go" {
631631
module, err := ctx.Prompt("Go module path (optional):")
@@ -634,7 +634,7 @@ func (p *ClientPlugin) initConfig(ctx cli.CommandContext) error {
634634
}
635635
config.Defaults.Module = module
636636
}
637-
637+
638638
// Save config
639639
configPath := ".forge-client.yml"
640640
if err := SaveClientConfig(config, configPath); err != nil {

cmd/forge/plugins/client_config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,3 @@ func autoDiscoverSpec(rootDir string, paths []string) (string, error) {
238238

239239
return "", fmt.Errorf("no spec file found in auto-discover paths")
240240
}
241-

0 commit comments

Comments
 (0)