Implement 'barn status' command #10

Closed
opened 2026-10-04 19:28:06 +00:00 by daniel · 1 comment
Owner

Imported from GitHub samson-media/barn#10 — opened by @daniel-samson on 2026-01-21 12:38:28 UTC

Overview

Implement the barn status command that shows the status of all jobs.

Context

  • Read first: README.md (barn status examples)
  • Depends on: #8 (CLI framework), #4 (job model)

Requirements

1. Status Command

com.samsonmedia.barn.cli.StatusCommand.java:

@Command(name = "status", description = "Show status of all jobs")
public class StatusCommand extends BaseCommand {
    @Option(names = {"--tag", "-t"}, description = "Filter by tag")
    private String tag;

    @Option(names = {"--state", "-s"}, description = "Filter by state")
    private JobState state;

    @Option(names = {"--limit", "-n"}, description = "Limit number of results")
    private Integer limit;

    @Override
    public Integer call() {
        // 1. Query jobs via IPC (or directly if --offline)
        // 2. Apply filters
        // 3. Output job list
    }
}

2. Usage Examples

# Show all jobs
barn status

# Filter by tag
barn status --tag=download

# Filter by state
barn status --state=running

# Limit results
barn status --limit=10

# JSON output
barn status --output=json

3. Human-Readable Output

Table format with columns:

ID         STATE      TAG         CREATED              EXIT    PID
job-9f83c  running    transcode   2026-01-21 18:40:01  -       12345
job-a7b2d  succeeded  download    2026-01-21 18:35:00  0       -
job-c4e1f  failed     upload      2026-01-21 18:30:00  1       -
job-d8e2g  queued     -           2026-01-21 18:45:00  -       -

Total: 4 jobs (1 running, 1 queued, 1 succeeded, 1 failed)

4. JSON Output

{
  "jobs": [
    {
      "id": "job-9f83c",
      "state": "running",
      "tag": "transcode",
      "created_at": "2026-01-21T18:40:01Z",
      "pid": 12345
    }
  ],
  "summary": {
    "total": 4,
    "running": 1,
    "queued": 1,
    "succeeded": 1,
    "failed": 1
  }
}

5. Sorting

Default sort: by created_at descending (newest first)

6. Tests Required

  • StatusCommandTest.java: Test output formatting, filtering
  • Integration test: Create jobs, verify status output

Acceptance Criteria

  • barn status shows all jobs
  • --tag filters by tag
  • --state filters by state
  • --limit limits results
  • Human output is a nice table
  • JSON/XML output is valid
  • Summary counts are accurate
  • mvn verify passes
  • Tests have 80%+ coverage

Implementation Notes

For the human-readable table, calculate column widths dynamically:

int maxIdLen = jobs.stream()
    .mapToInt(j -> j.id().length())
    .max()
    .orElse(10);

State colors (if TTY):

  • RUNNING: yellow
  • SUCCEEDED: green
  • FAILED: red
  • QUEUED: blue
  • CANCELED: gray

Definition of Done

  • Status shows all jobs correctly
  • Filtering works
  • Table formatting is clean
  • All tests pass
<!-- github-import:issue:10 --> _Imported from GitHub samson-media/barn#10 — opened by **@daniel-samson** on 2026-01-21 12:38:28 UTC_ ## Overview Implement the `barn status` command that shows the status of all jobs. ## Context - **Read first**: `README.md` (barn status examples) - **Depends on**: #8 (CLI framework), #4 (job model) ## Requirements ### 1. Status Command `com.samsonmedia.barn.cli.StatusCommand.java`: ```java @Command(name = "status", description = "Show status of all jobs") public class StatusCommand extends BaseCommand { @Option(names = {"--tag", "-t"}, description = "Filter by tag") private String tag; @Option(names = {"--state", "-s"}, description = "Filter by state") private JobState state; @Option(names = {"--limit", "-n"}, description = "Limit number of results") private Integer limit; @Override public Integer call() { // 1. Query jobs via IPC (or directly if --offline) // 2. Apply filters // 3. Output job list } } ``` ### 2. Usage Examples ```bash # Show all jobs barn status # Filter by tag barn status --tag=download # Filter by state barn status --state=running # Limit results barn status --limit=10 # JSON output barn status --output=json ``` ### 3. Human-Readable Output Table format with columns: ``` ID STATE TAG CREATED EXIT PID job-9f83c running transcode 2026-01-21 18:40:01 - 12345 job-a7b2d succeeded download 2026-01-21 18:35:00 0 - job-c4e1f failed upload 2026-01-21 18:30:00 1 - job-d8e2g queued - 2026-01-21 18:45:00 - - Total: 4 jobs (1 running, 1 queued, 1 succeeded, 1 failed) ``` ### 4. JSON Output ```json { "jobs": [ { "id": "job-9f83c", "state": "running", "tag": "transcode", "created_at": "2026-01-21T18:40:01Z", "pid": 12345 } ], "summary": { "total": 4, "running": 1, "queued": 1, "succeeded": 1, "failed": 1 } } ``` ### 5. Sorting Default sort: by created_at descending (newest first) ### 6. Tests Required - `StatusCommandTest.java`: Test output formatting, filtering - Integration test: Create jobs, verify status output ## Acceptance Criteria - [ ] `barn status` shows all jobs - [ ] `--tag` filters by tag - [ ] `--state` filters by state - [ ] `--limit` limits results - [ ] Human output is a nice table - [ ] JSON/XML output is valid - [ ] Summary counts are accurate - [ ] `mvn verify` passes - [ ] Tests have 80%+ coverage ## Implementation Notes For the human-readable table, calculate column widths dynamically: ```java int maxIdLen = jobs.stream() .mapToInt(j -> j.id().length()) .max() .orElse(10); ``` State colors (if TTY): - RUNNING: yellow - SUCCEEDED: green - FAILED: red - QUEUED: blue - CANCELED: gray ## Definition of Done - Status shows all jobs correctly - Filtering works - Table formatting is clean - All tests pass
daniel added this to the M3: CLI Commands milestone 2026-10-04 19:28:06 +00:00
daniel added the cli label 2026-10-04 19:28:06 +00:00
Author
Owner

@daniel-samson commented on 2026-01-21 13:38:46 UTC:

✅ Ticket #10 completed: Implemented 'barn status' command.

StatusCommand (src/main/java/com/samsonmedia/barn/cli/StatusCommand.java):

  • Extends BaseCommand for global options and output formatting
  • Options: --tag/-t, --state/-s, --limit/-n
  • Offline mode: Reads jobs directly from filesystem
  • Service mode: Shows message to start service

Features:

  • Lists all jobs with ID, state, tag, created time, exit code, PID
  • Filtering by tag (--tag=name)
  • Filtering by state (--state=QUEUED/RUNNING/SUCCEEDED/FAILED/CANCELED)
  • Limit results (--limit=N)
  • Sorted by creation time (newest first)
  • Summary showing total jobs and counts by state

Output formats:

  • HUMAN: Aligned table with headers, summary line
  • JSON: {jobs: [...], summary: {total, queued, running, ...}}
  • XML: Same structure as JSON

Tests (StatusCommandTest.java):

  • NoJobs: 1 test - empty message
  • WithJobs: 3 tests - show jobs, IDs, states
  • Filtering: 3 tests - tag, state, limit filters
  • OutputFormats: 3 tests - JSON, XML, human formats
  • Summary: 1 test - summary display
  • ServiceMode: 1 test - service not running message

All 496 tests passing. mvn verify successful.

<!-- github-import:comment:3778186955 --> _**@daniel-samson** commented on 2026-01-21 13:38:46 UTC:_ ✅ Ticket #10 completed: Implemented 'barn status' command. **StatusCommand** (src/main/java/com/samsonmedia/barn/cli/StatusCommand.java): - Extends BaseCommand for global options and output formatting - Options: --tag/-t, --state/-s, --limit/-n - Offline mode: Reads jobs directly from filesystem - Service mode: Shows message to start service **Features**: - Lists all jobs with ID, state, tag, created time, exit code, PID - Filtering by tag (--tag=name) - Filtering by state (--state=QUEUED/RUNNING/SUCCEEDED/FAILED/CANCELED) - Limit results (--limit=N) - Sorted by creation time (newest first) - Summary showing total jobs and counts by state **Output formats**: - HUMAN: Aligned table with headers, summary line - JSON: {jobs: [...], summary: {total, queued, running, ...}} - XML: Same structure as JSON **Tests** (StatusCommandTest.java): - NoJobs: 1 test - empty message - WithJobs: 3 tests - show jobs, IDs, states - Filtering: 3 tests - tag, state, limit filters - OutputFormats: 3 tests - JSON, XML, human formats - Summary: 1 test - summary display - ServiceMode: 1 test - service not running message All 496 tests passing. mvn verify successful.
This repo is archived. You cannot comment on issues.