timeout-cli 0.1.0

A simple and reliable command-line timeout utility
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# Justfile for timeout-cli project

# Default recipe - show available commands
default:
    @just --list

# Run all tests
test:
    cargo test --all-features

# Run tests with verbose output
test-verbose:
    cargo test --all-features -- --nocapture

# Check code formatting and linting
check:
    cargo fmt --check
    cargo clippy --all-targets --all-features -- -D warnings

# Format code
fmt:
    cargo fmt

# Run security audit
audit:
    @command -v cargo-audit >/dev/null || (echo "Installing cargo-audit..." && cargo install cargo-audit)
    cargo audit

# Generate and upload code coverage
coverage:
    #!/bin/bash
    echo "๐Ÿงช Generating code coverage..."
    
    # Check if cargo-tarpaulin is installed
    if ! command -v cargo-tarpaulin >/dev/null; then
        echo "Installing cargo-tarpaulin..."
        cargo install cargo-tarpaulin
    fi
    
    # Upload to Coveralls if token is available
    if [[ -n "$COVERALLS_REPO_TOKEN" ]]; then
        echo "๐Ÿ“Š Generating coverage and uploading to Coveralls..."
        cargo tarpaulin --coveralls "$COVERALLS_REPO_TOKEN"
        echo "โœ… Coverage uploaded to Coveralls"
    else
        echo "โš ๏ธ  COVERALLS_REPO_TOKEN not set - generating local coverage only"
        cargo tarpaulin
    fi

# Build in release mode
build-release:
    cargo build --release

# Clean build artifacts
clean:
    cargo clean

# Show current version
version:
    @echo "Current version: $(just _get-current-version)"

# Dry run cargo publish
publish-dry:
    cargo publish --dry-run

# Update version in Cargo.toml and run full release process
release version: (_check-clean) (_validate-version version) (_update-version version) (_test-and-check) (_publish-and-tag version)

# Internal: Check if working directory is clean
_check-clean:
    #!/bin/bash
    if [[ -n $(git status --porcelain) ]]; then
        echo "โŒ Working directory is not clean. Please commit or stash changes first."
        git status --short
        exit 1
    fi
    echo "โœ… Working directory is clean"

# Internal: Get current version from Cargo.toml
_get-current-version:
    @grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\([^"]*\)"/\1/'

# Internal: Validate new version is higher than current
_validate-version version:
    #!/bin/bash
    current_version=$(just _get-current-version)
    echo "๐Ÿ“Š Current version: $current_version"
    echo "๐Ÿ“Š New version: {{version}}"
    
    # Function to compare semantic versions
    version_compare() {
        if [[ $1 == $2 ]]; then
            return 1  # Equal
        fi
        
        local IFS=.
        local i ver1=($1) ver2=($2)
        
        # Fill empty fields with zeros
        for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
            ver1[i]=0
        done
        for ((i=${#ver2[@]}; i<${#ver1[@]}; i++)); do
            ver2[i]=0
        done
        
        for ((i=0; i<${#ver1[@]}; i++)); do
            if [[ -z ${ver2[i]} ]]; then
                ver2[i]=0
            fi
            if ((10#${ver1[i]} > 10#${ver2[i]})); then
                return 2  # ver1 > ver2
            fi
            if ((10#${ver1[i]} < 10#${ver2[i]})); then
                return 0  # ver1 < ver2
            fi
        done
        return 1  # Equal
    }
    
    version_compare "$current_version" "{{version}}"
    result=$?
    
    case $result in
        0)
            echo "โœ… Version {{version}} is higher than current version $current_version"
            ;;
        1)
            echo "โŒ Version {{version}} is the same as current version $current_version"
            echo "   Please use a higher version number"
            exit 1
            ;;
        2)
            echo "โŒ Version {{version}} is lower than current version $current_version"
            echo "   Please use a higher version number"
            exit 1
            ;;
    esac
    
    # Also check if version already exists as a git tag
    if git rev-parse "v{{version}}" >/dev/null 2>&1; then
        echo "โŒ Git tag v{{version}} already exists"
        echo "   Choose a different version number"
        exit 1
    fi
    
    # Check if version exists on crates.io
    echo "๐Ÿ” Checking if version {{version}} exists on crates.io..."
    if curl -s "https://crates.io/api/v1/crates/timeout-cli" | jq -e ".versions[] | select(.num == \"{{version}}\")" >/dev/null 2>&1; then
        echo "โŒ Version {{version}} already exists on crates.io"
        echo "   Choose a different version number"
        exit 1
    fi
    
    echo "โœ… Version {{version}} is valid for release"

# Internal: Update version in Cargo.toml
_update-version version:
    #!/bin/bash
    echo "๐Ÿ“ Updating version to {{version}}"
    
    # Update Cargo.toml
    sed -i.bak 's/^version = "[^"]*"/version = "{{version}}"/' Cargo.toml
    rm Cargo.toml.bak
    
    # Update Cargo.lock
    cargo check --quiet
    
    # Stage the version changes
    git add Cargo.toml Cargo.lock
    git commit -m "Bump version to {{version}}"
    
    echo "โœ… Version updated to {{version}}"

# Internal: Run tests and checks before release
_test-and-check:
    #!/bin/bash
    echo "๐Ÿงช Running tests and checks..."
    
    # Run all tests
    echo "  โ†’ Running tests..."
    cargo test --all-features --quiet
    
    # Check formatting
    echo "  โ†’ Checking code formatting..."
    cargo fmt --check
    
    # Check linting
    echo "  โ†’ Running clippy..."
    cargo clippy --all-targets --all-features --quiet -- -D warnings
    
    # Security audit
    echo "  โ†’ Running security audit..."
    cargo audit --quiet
    
    # Dry run publish
    echo "  โ†’ Testing cargo publish..."
    cargo publish --dry-run --quiet
    
    echo "โœ… All checks passed"

# Internal: Publish to crates.io and create git tag
_publish-and-tag version:
    #!/bin/bash
    echo "๐Ÿš€ Publishing and tagging release {{version}}"
    
    # Push version commit first
    echo "  โ†’ Pushing version commit to GitHub..."
    git push origin main
    
    # Publish to crates.io
    echo "  โ†’ Publishing to crates.io..."
    cargo publish
    
    # Wait a moment for crates.io to process
    sleep 5
    
    # Create and push tag
    echo "  โ†’ Creating and pushing tag v{{version}}..."
    git tag "v{{version}}"
    git push origin "v{{version}}"
    
    echo "โœ… Release {{version}} published successfully!"
    echo ""
    echo "๐Ÿ“ฆ The GitHub Actions release workflow will now:"
    echo "   โ€ข Build binaries for all platforms"
    echo "   โ€ข Create GitHub release with changelog"
    echo "   โ€ข Upload binary assets for cargo-binstall"
    echo ""
    echo "๐ŸŽ‰ Users can install with: cargo binstall timeout-cli"

# Quick release command that prompts for version
release-interactive:
    #!/bin/bash
    echo "๐Ÿš€ Interactive Release Process"
    echo ""
    
    # Get current version from Cargo.toml
    current_version=$(just _get-current-version)
    echo "Current version: $current_version"
    echo ""
    
    # Suggest next versions
    IFS='.' read -ra VERSION_PARTS <<< "$current_version"
    major=${VERSION_PARTS[0]}
    minor=${VERSION_PARTS[1]}
    patch=${VERSION_PARTS[2]}
    
    next_patch="$major.$minor.$((patch + 1))"
    next_minor="$major.$((minor + 1)).0"
    next_major="$((major + 1)).0.0"
    
    echo "Suggested versions:"
    echo "  1. Patch: $next_patch (bug fixes)"
    echo "  2. Minor: $next_minor (new features, backwards compatible)"
    echo "  3. Major: $next_major (breaking changes)"
    echo ""
    
    read -p "Enter new version (1/2/3 or custom version, Enter for patch): " choice
    
    case "$choice" in
        "1" | "")
            new_version="$next_patch"
            ;;
        "2")
            new_version="$next_minor"
            ;;
        "3")
            new_version="$next_major"
            ;;
        *)
            new_version="$choice"
            ;;
    esac
    
    echo ""
    echo "๐ŸŽฏ Selected version: $new_version"
    echo ""
    
    # Show what will happen
    echo "This will:"
    echo "  โœ“ Validate version is higher than current ($current_version)"
    echo "  โœ“ Update Cargo.toml to version $new_version"
    echo "  โœ“ Run full test suite and checks"
    echo "  โœ“ Publish to crates.io"
    echo "  โœ“ Create and push git tag v$new_version"
    echo "  โœ“ Trigger GitHub Actions for binary builds"
    echo ""
    
    read -p "Continue with release? (y/N): " confirm
    
    if [[ "$confirm" =~ ^[Yy]$ ]]; then
        just release "$new_version"
    else
        echo "โŒ Release cancelled"
        exit 1
    fi

# Check release status after tagging
check-release version:
    #!/bin/bash
    echo "๐Ÿ“Š Checking release status for v{{version}}"
    echo ""
    
    # Check if tag exists
    if git rev-parse "v{{version}}" >/dev/null 2>&1; then
        echo "โœ… Git tag v{{version}} exists"
    else
        echo "โŒ Git tag v{{version}} not found"
        exit 1
    fi
    
    # Check crates.io
    echo "๐Ÿ” Checking crates.io..."
    if curl -s "https://crates.io/api/v1/crates/timeout-cli" | jq -e ".versions[] | select(.num == \"{{version}}\")"; then
        echo "โœ… Version {{version}} published on crates.io"
    else
        echo "โณ Version {{version}} not yet available on crates.io (may take a few minutes)"
    fi
    
    # Check GitHub release
    echo "๐Ÿ” Checking GitHub release..."
    if curl -s "https://api.github.com/repos/yaleman/timeout-cli/releases/tags/v{{version}}" | jq -e ".tag_name"; then
        echo "โœ… GitHub release v{{version}} created"
        echo "๐Ÿ”— https://github.com/yaleman/timeout-cli/releases/tag/v{{version}}"
    else
        echo "โณ GitHub release v{{version}} not yet created (Actions may still be running)"
        echo "๐Ÿ”— Check: https://github.com/yaleman/timeout-cli/actions"
    fi

# Test cargo-binstall installation (after release)
test-binstall:
    #!/bin/bash
    echo "๐Ÿงช Testing cargo-binstall installation"
    echo ""
    
    # Create temporary directory
    temp_dir=$(mktemp -d)
    cd "$temp_dir"
    
    echo "  โ†’ Installing timeout-cli via cargo-binstall..."
    if cargo binstall timeout-cli --no-confirm; then
        echo "โœ… Installation successful"
        
        echo "  โ†’ Testing basic functionality..."
        timeout --version
        timeout 1 echo "Hello from timeout-cli!"
        
        echo "โœ… cargo-binstall installation working correctly!"
    else
        echo "โŒ cargo-binstall installation failed"
        exit 1
    fi
    
    # Cleanup
    cd - > /dev/null
    rm -rf "$temp_dir"

# Show current project status
status:
    #!/bin/bash
    echo "๐Ÿ“Š timeout-cli Project Status"
    echo "=============================="
    echo ""
    
    # Version info
    version=$(just _get-current-version)
    echo "๐Ÿ“ฆ Current version: $version"
    
    # Git status
    echo "๐Ÿ“ Git status:"
    if [[ -n $(git status --porcelain) ]]; then
        echo "   โš ๏ธ  Working directory has changes"
        git status --short | sed 's/^/   /'
    else
        echo "   โœ… Working directory clean"
    fi
    
    # Last commit
    echo "๐Ÿ”€ Last commit: $(git log -1 --pretty=format:'%h %s (%cr)')"
    
    # Remote status
    echo "๐ŸŒ Remote status:"
    if git remote get-url origin &>/dev/null; then
        echo "   ๐Ÿ“ Origin: $(git remote get-url origin)"
        
        # Check if we're ahead/behind
        git fetch origin main --quiet
        ahead=$(git rev-list --count origin/main..HEAD 2>/dev/null || echo "0")
        behind=$(git rev-list --count HEAD..origin/main 2>/dev/null || echo "0")
        
        if [[ "$ahead" -gt 0 ]]; then
            echo "   โฌ†๏ธ  $ahead commits ahead of origin/main"
        fi
        if [[ "$behind" -gt 0 ]]; then
            echo "   โฌ‡๏ธ  $behind commits behind origin/main"
        fi
        if [[ "$ahead" -eq 0 && "$behind" -eq 0 ]]; then
            echo "   โœ… Up to date with origin/main"
        fi
    else
        echo "   โŒ No remote origin configured"
    fi
    
    echo ""
    echo "๐Ÿš€ Ready to release? Run: just release-interactive"