Release-list CLI project
Request
Harbor Media's release coordinator needs a predictable artifact-list command.
Data
The supplied text contains one artifact label per line, with duplicate labels and blank lines. The supplied argv contains only documented flags. No network or host file access is needed.
Finished result
Return the exact selected lines with optional output count. Preserve the order of transformations: clean, prefix, unique, sort, limit, count. The function is the command's testable core; installing an executable is outside this workspace.
Harbor Media keeps release artifacts in a text file assembled by several teams. The release coordinator needs a small command that trims that file, selects a prefix, removes duplicates when requested, sorts when requested, and limits the output. You'll build the pure core of that command in six steps. Your function receives an argument list and file text rather than reading process arguments or a host path. That boundary keeps the same logic testable in the browser and reusable in a real command wrapper later. Each step starts from your previous code. The final output includes an optional count that must describe exactly what the command returned.
import argparse
def release_cli(argv, text):
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--prefix", default="")
parser.add_argument("--unique", action="store_true")
parser.add_argument("--sort", action="store_true")
parser.add_argument("--limit", type=int, default=-1)
parser.add_argument("--count", action="store_true")
options = parser.parse_args(argv)
lines = [line.strip() for line in text.splitlines() if line.strip()]
return "\n".join(lines)
The parser accepts --prefix TEXT, --unique, --sort, --limit N (default -1), and --count. Use argparse.ArgumentParser(add_help=False) and parse_args(argv). With text z\na\nz, the finished command ['--unique', '--sort', '--count'] returns a\nz\ncount=2.