@@ -265,27 +265,13 @@ var devCommand = cli.Command{
265265 Value : false ,
266266 Usage : "Run in 'watch' mode to loop and rebuild when files change." ,
267267 },
268- & cli.BoolFlag {
269- Name : "lint" ,
270- Aliases : []string {"l" },
271- Value : false ,
272- Usage : "Only check for diagnostic errors without running a full build." ,
273- },
274268 },
275269 Action : runPreview ,
276270}
277271
278272func runPreview (ctx context.Context , cmd * cli.Command ) error {
279273 cc := getAPICommandContext (cmd )
280274
281- openapiSpecPath := cmd .String ("openapi-spec" )
282- stainlessConfigPath := cmd .String ("stainless-config" )
283-
284- // If only linting is requested, run in lint-only mode
285- if cmd .Bool ("lint" ) {
286- return runLintLoop (ctx , cmd )
287- }
288-
289275 gitUser , err := getGitUsername ()
290276 if err != nil {
291277 Warn ("Couldn't get a git user: %s" , err )
@@ -366,7 +352,7 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
366352 for {
367353 // Keep checking diagnostics until they're all fixed
368354 for {
369- diagnostics , err := getPreviewDiagnostics (ctx , cmd )
355+ diagnostics , err := getDiagnostics (ctx , cmd , cc )
370356 if err != nil {
371357 if errors .Is (err , ErrUserCancelled ) {
372358 return nil
@@ -380,7 +366,7 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
380366
381367 if hasBlockingDiagnostic (diagnostics ) {
382368 fmt .Println ("\n Diagnostic checks will re-run once you edit your configuration files..." )
383- if err := waitTillAnyFileChanged (ctx , [] string { openapiSpecPath , stainlessConfigPath } ); err != nil {
369+ if err := waitTillConfigChanges (ctx , cmd , cc ); err != nil {
384370 return err
385371 }
386372 continue
@@ -404,35 +390,17 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
404390 return nil
405391}
406392
407- // runLintLoop handles linting in a loop for watch mode
408- func runLintLoop (ctx context.Context , cmd * cli.Command ) error {
409- // Get the initial file modification times
410- openapiSpecPath := cmd .String ("openapi-spec" )
411- stainlessConfigPath := cmd .String ("stainless-config" )
412-
413- for {
414- diagnostics , err := getPreviewDiagnosticsJSON (ctx , cmd )
415- if err != nil {
416- if errors .Is (err , ErrUserCancelled ) {
417- return nil
418- }
419- return err
420- }
421- jsonObj := gjson .Parse (diagnostics .Raw )
422- ShowJSON ("Diagnostics" , jsonObj , cmd .String ("format" ), cmd .String ("transform" ))
423-
424- if ! cmd .Bool ("watch" ) {
425- break
426- }
427-
428- if err := waitTillAnyFileChanged (ctx , []string {openapiSpecPath , stainlessConfigPath }); err != nil {
429- return err
430- }
393+ func waitTillConfigChanges (ctx context.Context , cmd * cli.Command , cc * apiCommandContext ) error {
394+ openapiSpecPath := cc .workspaceConfig .OpenAPISpec
395+ if cmd .IsSet ("openapi-spec" ) {
396+ openapiSpecPath = cmd .String ("openapi-spec" )
397+ }
398+ stainlessConfigPath := cc .workspaceConfig .StainlessConfig
399+ if cmd .IsSet ("stainless-config" ) {
400+ stainlessConfigPath = cmd .String ("stainless-config" )
431401 }
432- return nil
433- }
434402
435- func waitTillAnyFileChanged ( ctx context. Context , files []string ) error {
403+ files := []string { openapiSpecPath , stainlessConfigPath }
436404 lastModified := make (map [string ]time.Time )
437405 for _ , file := range files {
438406 if stat , err := os .Stat (file ); err == nil {
@@ -528,19 +496,32 @@ func getCurrentGitBranch() (string, error) {
528496 return branch , nil
529497}
530498
531- func getPreviewDiagnosticsJSON (ctx context.Context , cmd * cli.Command ) (* gjson.Result , error ) {
532- cc := getAPICommandContext (cmd )
499+ func getDiagnostics (ctx context.Context , cmd * cli.Command , cc * apiCommandContext ) ([]stainless.BuildDiagnostic , error ) {
533500 var specParams GenerateSpecParams
534- specParams .Project = cmd .String ("project" )
501+ if cmd .IsSet ("project" ) {
502+ specParams .Project = cmd .String ("project" )
503+ } else {
504+ specParams .Project = cc .workspaceConfig .Project
505+ }
535506 specParams .Source .Type = "upload"
536507
537- stainlessConfig , err := os .ReadFile (cmd .String ("stainless-config" ))
508+ configPath := cc .workspaceConfig .StainlessConfig
509+ if cmd .IsSet ("stainless-config" ) {
510+ configPath = cmd .String ("stainless-config" )
511+ }
512+
513+ stainlessConfig , err := os .ReadFile (configPath )
538514 if err != nil {
539515 return nil , err
540516 }
541517 specParams .Source .StainlessConfig = string (stainlessConfig )
542518
543- openAPISpec , err := os .ReadFile (cmd .String ("openapi-spec" ))
519+ oasPath := cc .workspaceConfig .OpenAPISpec
520+ if cmd .IsSet ("openapi-spec" ) {
521+ oasPath = cmd .String ("openapi-spec" )
522+ }
523+
524+ openAPISpec , err := os .ReadFile (oasPath )
544525 if err != nil {
545526 return nil , err
546527 }
@@ -551,21 +532,12 @@ func getPreviewDiagnosticsJSON(ctx context.Context, cmd *cli.Command) (*gjson.Re
551532 if err != nil {
552533 return nil , err
553534 }
554- json := gjson .ParseBytes (result )
555- diagnostics := json .Get ("spec.diagnostics.@values.@flatten" )
556- return & diagnostics , nil
557- }
558535
559- func getPreviewDiagnostics (ctx context.Context , cmd * cli.Command ) ([]stainless.BuildDiagnostic , error ) {
560- jsonDiagnostics , err := getPreviewDiagnosticsJSON (ctx , cmd )
561- if err != nil {
562- return nil , err
563- }
536+ transform := "spec.diagnostics.@values.@flatten.#(ignored==false)#"
537+ jsonObj := gjson .Parse (string (result )).Get (transform )
564538 var diagnostics []stainless.BuildDiagnostic
565- if err := json .Unmarshal ([]byte (jsonDiagnostics .Raw ), & diagnostics ); err != nil {
566- return nil , err
567- }
568- return diagnostics , err
539+ json .Unmarshal ([]byte (jsonObj .Raw ), & diagnostics )
540+ return diagnostics , nil
569541}
570542
571543func hasBlockingDiagnostic (diagnostics []stainless.BuildDiagnostic ) bool {
0 commit comments