Skip to content

Build ordercli — CLI app for order management (create, view, list) #1

Open

Description

@anujkumar-df

Summary

Build a CLI application called ordercli that allows creating, viewing, and listing orders. This is the first entry point into the OMS and should follow DDD principles as defined in CLAUDE.md. Orders are persisted to a local store so they survive process restarts.

Details

CLI Commands

Command Description
ordercli create --customer <id> --item "productId,quantity,unitPrice" [--item ...] Create a new order
ordercli view --id <orderId> View a single order by ID
ordercli list List all orders

Line Items

  • Passed as repeated --item flags in the format "productId,quantity,unitPrice"
  • Example: --item "PROD01,3,10.00" --item "PROD02,2,25.00"

Output Format

All output is JSON for machine readability. Every response has a "status" field ("success" or "error").

Order ID Generation

  • Auto-generated sequential IDs: ORD-0001, ORD-0002, etc.

Order Status

  • All newly created orders start with status "DRAFT"

Persistence

  • Orders must persist across process restarts (use a local file-based store, e.g. JSON file)

Validation Rules

Rule Error message
Missing --customer flag "Customer ID is required"
No --item flags provided "At least one line item is required"
Quantity is zero or negative "Invalid quantity for {productId}: must be greater than 0"
Unit price is negative "Invalid unit price for {productId}: must be >= 0"
Duplicate product ID across items "Duplicate product ID: {productId}"
Malformed item format (not 3 parts) "Invalid item format '{raw}': expected 'productId,quantity,unitPrice'"

Calculated Fields

  • subtotal per line item = quantity * unitPrice
  • total on order = sum of all subtotals
  • createdAt = ISO 8601 timestamp at time of creation

Scope

  • Domain layer: Order aggregate, OrderLineItem value object, order validation invariants
  • Application layer: CreateOrder, ViewOrder, ListOrders use cases
  • Infrastructure layer: File-based order repository, CLI argument parsing
  • Follow DDD project structure as defined in CLAUDE.md: src/order/domain/, src/order/application/, src/order/infrastructure/, src/order/api/

Verification Tests

Run these commands in sequence to verify correctness:

Test 1: Happy path — single item

ordercli create --customer "CUST001" --item "PROD01,3,10.00"
{
  "status": "success",
  "order": {
    "orderId": "ORD-0001",
    "customerId": "CUST001",
    "status": "DRAFT",
    "items": [
      {"productId": "PROD01", "quantity": 3, "unitPrice": 10.00, "subtotal": 30.00}
    ],
    "total": 30.00,
    "createdAt": "2026-02-15T12:00:00Z"
  }
}

Test 2: Happy path — multiple items

ordercli create --customer "CUST001" --item "PROD01,3,10.00" --item "PROD02,2,25.00"
{
  "status": "success",
  "order": {
    "orderId": "ORD-0002",
    "customerId": "CUST001",
    "status": "DRAFT",
    "items": [
      {"productId": "PROD01", "quantity": 3, "unitPrice": 10.00, "subtotal": 30.00},
      {"productId": "PROD02", "quantity": 2, "unitPrice": 25.00, "subtotal": 50.00}
    ],
    "total": 80.00,
    "createdAt": "2026-02-15T12:00:01Z"
  }
}

Test 3: No line items

ordercli create --customer "CUST001"
{"status": "error", "error": "At least one line item is required"}

Test 4: Zero quantity

ordercli create --customer "CUST001" --item "PROD01,0,10.00"
{"status": "error", "error": "Invalid quantity for PROD01: must be greater than 0"}

Test 5: Negative quantity

ordercli create --customer "CUST001" --item "PROD01,-2,10.00"
{"status": "error", "error": "Invalid quantity for PROD01: must be greater than 0"}

Test 6: Negative price

ordercli create --customer "CUST001" --item "PROD01,3,-5.00"
{"status": "error", "error": "Invalid unit price for PROD01: must be >= 0"}

Test 7: Missing customer

ordercli create --item "PROD01,3,10.00"
{"status": "error", "error": "Customer ID is required"}

Test 8: Duplicate product ID

ordercli create --customer "CUST001" --item "PROD01,3,10.00" --item "PROD01,2,10.00"
{"status": "error", "error": "Duplicate product ID: PROD01"}

Test 9: Malformed item format

ordercli create --customer "CUST001" --item "PROD01,3"
{"status": "error", "error": "Invalid item format 'PROD01,3': expected 'productId,quantity,unitPrice'"}

Test 10: View order

ordercli view --id "ORD-0001"
{
  "status": "success",
  "order": {
    "orderId": "ORD-0001",
    "customerId": "CUST001",
    "status": "DRAFT",
    "items": [
      {"productId": "PROD01", "quantity": 3, "unitPrice": 10.00, "subtotal": 30.00}
    ],
    "total": 30.00,
    "createdAt": "2026-02-15T12:00:00Z"
  }
}

Test 11: View non-existent order

ordercli view --id "ORD-9999"
{"status": "error", "error": "Order not found: ORD-9999"}

Test 12: List orders

ordercli list
{
  "status": "success",
  "orders": [
    {"orderId": "ORD-0001", "customerId": "CUST001", "status": "DRAFT", "total": 30.00, "createdAt": "2026-02-15T12:00:00Z"},
    {"orderId": "ORD-0002", "customerId": "CUST001", "status": "DRAFT", "total": 80.00, "createdAt": "2026-02-15T12:00:01Z"}
  ],
  "count": 2
}

Test 13: List when empty (fresh DB)

ordercli list
{"status": "success", "orders": [], "count": 0}

Test 14: Persistence across restart

ordercli create --customer "CUST001" --item "PROD01,1,5.00"
# restart / kill and relaunch process
ordercli list
# Expected: the created order appears in the list

Activity

  1. Repository owner deleted a comment from github-actions on Feb 15, 2026
  2. Repository owner deleted a comment from github-actions on Feb 15, 2026
  3. Repository owner deleted a comment from github-actions on Feb 15, 2026
  4. added a commit that references this issue on Feb 15, 2026
    b42cb9c
  5. github-actions commented on Feb 15, 2026

    @github-actions

    Implementation Complete

    Branch cursor/issue-1 has been pushed with the full ordercli implementation following DDD principles.

    What was built

    Layer Path Contents
    Domain src/order/domain/ Order aggregate root, OrderLineItem value object, OrderRepository interface
    Application src/order/application/ CreateOrder, ViewOrder, ListOrders use cases
    Infrastructure src/order/infrastructure/ FileOrderRepository — JSON file persistence
    API src/order/api/ CLI entry point with Commander.js

    Features

    • All 3 CLI commands: create, view, list
    • Sequential order IDs (ORD-0001, ORD-0002, ...)
    • All 6 validation rules with exact error messages
    • JSON output with status field
    • Persistence across restarts via local file store (~/.oms-5k/orders.json)

    Verification

    All 14 verification tests from the issue pass successfully.

    PR creation

    The GitHub Actions token does not have permission to create pull requests in this repository. Please create the PR manually from branch cursor/issue-1 → main:

    👉 Create Pull Request

  6. anujkumar-df commented on Feb 15, 2026

    @anujkumar-df
    OwnerAuthor

    I want to use Python, create a new branch, and implement the requirements.

  7. github-actions commented on Feb 15, 2026

    @github-actions

    Python Implementation Complete

    As requested, the ordercli CLI has been re-implemented in Python on branch cursor/issue-1-python.

    What was built

    Layer Path Contents
    Domain src/order/domain/ Order aggregate root, OrderLineItem value object, OrderRepository interface
    Application src/order/application/ CreateOrder, ViewOrder, ListOrders use cases
    Infrastructure src/order/infrastructure/ FileOrderRepository — JSON file persistence (~/.oms-5k/orders.json)
    API src/order/api/ CLI entry point with argparse

    Installation

    pip install -e .
    ordercli create --customer "CUST001" --item "PROD01,3,10.00"

    Verification

    All 14 verification tests from the issue pass successfully.

    PR

    The GitHub Actions token does not have permission to create pull requests. Please create the PR manually from branch cursor/issue-1-python → main:

    👉 Create Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions