Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ export WAITFOR_MAX_INTERVAL=30
waitfor npm start
```

### Verbose Output
Enable detailed progress information during resource checks:
```bash
# Show progress information while waiting for resources
waitfor --verbose -r postgres://localhost:5432/db -r http://localhost:8080 npm start

# Or use environment variable
export WAITFOR_VERBOSE=true
waitfor -r http://localhost:8080 ./start-app.sh
```

## Configuration

### Command Line Options
Expand All @@ -112,6 +123,7 @@ waitfor npm start
| `--attempts` | `-a` | Number of connection attempts | `5` | `WAITFOR_ATTEMPTS` |
| `--interval` | - | Initial interval between attempts (seconds) | `5` | `WAITFOR_INTERVAL` |
| `--max-interval` | - | Maximum interval between attempts (seconds) | `60` | `WAITFOR_MAX_INTERVAL` |
| `--verbose` | - | Enable verbose progress output | `false` | `WAITFOR_VERBOSE` |
| `--help` | `-h` | Show help | - | - |
| `--version` | `-v` | Show version | - | - |

Expand All @@ -134,6 +146,7 @@ GLOBAL OPTIONS:
--attempts value, -a value amount of attempts (default: 5) [$WAITFOR_ATTEMPTS]
--interval value interval between attempts (sec) (default: 5) [$WAITFOR_INTERVAL]
--max-interval value maximum interval between attempts (sec) (default: 60) [$WAITFOR_MAX_INTERVAL]
--verbose enable verbose progress output (default: false) [$WAITFOR_VERBOSE]
--help, -h show help (default: false)
--version, -v print the version (default: false)

Expand Down
42 changes: 39 additions & 3 deletions waitfor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-waitfor/waitfor-proc"
"github.com/urfave/cli/v2"
"os"
"time"
)

var version string
Expand Down Expand Up @@ -48,6 +49,11 @@ func main() {
EnvVars: []string{"WAITFOR_MAX_INTERVAL"},
Value: 60,
},
&cli.BoolFlag{
Name: "verbose",
Usage: "enable verbose progress output",
EnvVars: []string{"WAITFOR_VERBOSE"},
},
},
Action: func(ctx *cli.Context) error {
if ctx.NArg() == 0 {
Expand Down Expand Up @@ -77,12 +83,42 @@ func main() {
program.Args = args[1:]
}

out, err := runner.Run(
ctx.Context,
program,
// Build waitfor options
options := []waitfor.Option{
waitfor.WithAttempts(ctx.Uint64("attempts")),
waitfor.WithInterval(ctx.Uint64("interval")),
waitfor.WithMaxInterval(ctx.Uint64("max-interval")),
}

// If verbose mode is enabled, show progress
if ctx.Bool("verbose") {
fmt.Printf("waitfor: checking %d resource(s) with %d max attempts\n", len(program.Resources), ctx.Uint64("attempts"))
for i, resource := range program.Resources {
fmt.Printf("waitfor: [%d/%d] checking %s\n", i+1, len(program.Resources), resource)
}
fmt.Printf("waitfor: retry interval: %ds, max interval: %ds\n", ctx.Uint64("interval"), ctx.Uint64("max-interval"))
fmt.Println("waitfor: starting resource availability tests...")

start := time.Now()

// Test resources first to show progress
err := runner.Test(ctx.Context, program.Resources, options...)

duration := time.Since(start)

if err != nil {
fmt.Printf("waitfor: resource tests failed after %v: %v\n", duration.Round(time.Millisecond), err)
return err
}

fmt.Printf("waitfor: all resources available after %v\n", duration.Round(time.Millisecond))
fmt.Printf("waitfor: executing command: %s\n", program.Executable)
}

out, err := runner.Run(
ctx.Context,
program,
options...,
)

if out != nil {
Expand Down