Implement a command-line tool named ch-placement-lookup that meets the following specifications:
Functionality
The tool should manage the placement of items in a structure based on a multi-ring model.
It should accept the following parameters:
placement_type: A string identifier for the placement strategy (only "multiring" is recognized).
num_items: An integer that specifies the total number of items to place.
num_rings: An integer representing the total number of rings in which the items will be distributed.
max_per_ring: An integer setting the maximum number of items that can be placed in a single ring.
offset: An integer to define the starting position or offset for placing items.
The tool must return an exit code of 0 if the operation is successful, and a non-zero exit code if there are any issues.
Expected Inputs
The first input will be a string "multiring" (for placement_type).
The second input will be an integer (num_items).
The third input will be an integer (num_rings).
The fourth input will be an integer (max_per_ring).
The fifth input will be an integer (offset).
Expected Outputs
On successful execution, the tool should output a structured format of how items are placed in the multi-ring structure. If the specified conditions are not met (e.g., if num_items exceeds num_rings * max_per_ring), print an appropriate error message to stdout and return a non-zero exit code.
File Locations and Naming
Place your implementation file as ch-placement-lookup in the /app/ directory.
Ensure that the script is executable (i.e., have the correct permissions set).
Upon completion, run the verifier script to ensure your implementation passes all tests.
Tests
The following test script will be used to verify your solution:
bash
#!/bin/bash
src/ch-placement-lookup multiring 256 1 100 3
if [ $? -ne 0 ]; then
exit 1
fi
src/ch-placement-lookup multiring 256 16 100 3
if [ $? -ne 0 ]; then
exit 1
fi