Skip to content
Merged
2 changes: 2 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ stl builds create --branch <branch>`,

&devCommand,

&lintCommand,

{
Name: "@manpages",
Usage: "Generate documentation for 'man'",
Expand Down
62 changes: 62 additions & 0 deletions pkg/cmd/configwatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cmd

import (
"context"
"fmt"
"os"
"time"

"github.com/urfave/cli/v3"
)

type configChangedEvent struct{}

func waitTillConfigChanges(ctx context.Context, cmd *cli.Command, cc *apiCommandContext) error {
openapiSpecPath := cc.workspaceConfig.OpenAPISpec
if cmd.IsSet("openapi-spec") {
openapiSpecPath = cmd.String("openapi-spec")
}
stainlessConfigPath := cc.workspaceConfig.StainlessConfig
if cmd.IsSet("stainless-config") {
stainlessConfigPath = cmd.String("stainless-config")
}

// Get initial file modification times
openapiSpecInfo, err := os.Stat(openapiSpecPath)
if err != nil {
return fmt.Errorf("failed to get file info for %s: %v", openapiSpecPath, err)
}
openapiSpecModTime := openapiSpecInfo.ModTime()

stainlessConfigInfo, err := os.Stat(stainlessConfigPath)
if err != nil {
return fmt.Errorf("failed to get file info for %s: %v", stainlessConfigPath, err)
}
stainlessConfigModTime := stainlessConfigInfo.ModTime()

// Poll for file changes every 250ms
ticker := time.NewTicker(250 * time.Millisecond)
defer ticker.Stop()

for {
select {
case <-ticker.C:
// Check OpenAPI spec file
if info, err := os.Stat(openapiSpecPath); err == nil {
if info.ModTime().After(openapiSpecModTime) {
return nil
}
}

// Check Stainless config file
if info, err := os.Stat(stainlessConfigPath); err == nil {
if info.ModTime().After(stainlessConfigModTime) {
return nil
}
}

case <-ctx.Done():
return ctx.Err()
}
}
}
Loading