Skip to content

Commit 654c0f8

Browse files
authored
Merge pull request #59 from stainless-api/bruce-hill/local-diagnostics
feat(stl): add lint command for fast diagnostics
2 parents 5e89b57 + eaffe47 commit 654c0f8

File tree

6 files changed

+531
-97
lines changed

6 files changed

+531
-97
lines changed

pkg/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ stl builds create --branch <branch>`,
162162

163163
&devCommand,
164164

165+
&lintCommand,
166+
165167
{
166168
Name: "@manpages",
167169
Usage: "Generate documentation for 'man'",

pkg/cmd/configwatcher.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"time"
8+
9+
"github.com/urfave/cli/v3"
10+
)
11+
12+
type configChangedEvent struct{}
13+
14+
func waitTillConfigChanges(ctx context.Context, cmd *cli.Command, cc *apiCommandContext) error {
15+
openapiSpecPath := cc.workspaceConfig.OpenAPISpec
16+
if cmd.IsSet("openapi-spec") {
17+
openapiSpecPath = cmd.String("openapi-spec")
18+
}
19+
stainlessConfigPath := cc.workspaceConfig.StainlessConfig
20+
if cmd.IsSet("stainless-config") {
21+
stainlessConfigPath = cmd.String("stainless-config")
22+
}
23+
24+
// Get initial file modification times
25+
openapiSpecInfo, err := os.Stat(openapiSpecPath)
26+
if err != nil {
27+
return fmt.Errorf("failed to get file info for %s: %v", openapiSpecPath, err)
28+
}
29+
openapiSpecModTime := openapiSpecInfo.ModTime()
30+
31+
stainlessConfigInfo, err := os.Stat(stainlessConfigPath)
32+
if err != nil {
33+
return fmt.Errorf("failed to get file info for %s: %v", stainlessConfigPath, err)
34+
}
35+
stainlessConfigModTime := stainlessConfigInfo.ModTime()
36+
37+
// Poll for file changes every 250ms
38+
ticker := time.NewTicker(250 * time.Millisecond)
39+
defer ticker.Stop()
40+
41+
for {
42+
select {
43+
case <-ticker.C:
44+
// Check OpenAPI spec file
45+
if info, err := os.Stat(openapiSpecPath); err == nil {
46+
if info.ModTime().After(openapiSpecModTime) {
47+
return nil
48+
}
49+
}
50+
51+
// Check Stainless config file
52+
if info, err := os.Stat(stainlessConfigPath); err == nil {
53+
if info.ModTime().After(stainlessConfigModTime) {
54+
return nil
55+
}
56+
}
57+
58+
case <-ctx.Done():
59+
return ctx.Err()
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)