Add sort-yaml-key tool, reformat README as tools table - #11
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds the missing sort-yaml-key CLI tool to the repository and restructures the root README “Tools” section into a single alphabetical table to make discovery and linking more consistent.
Changes:
- Added the
sort-yaml-keyPython CLI (plus its README) for sorting YAML lists by a specified key. - Reformatted the root
README.mdTools section into a flat alphabetical table with metadata columns.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
sort-yaml-key/sort-yaml-key |
New CLI script that loads a YAML list, sorts items by a key, and emits reordered YAML. |
sort-yaml-key/README.md |
Usage/options/docs for the new sort-yaml-key tool. |
README.md |
Replaces categorized bullets with an alphabetical tools table and adds an entry for sort-yaml-key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Parse the arguments | ||
| args = parser.parse_args() | ||
|
|
||
| # Load the YAML data from the file | ||
| with open(args.filename, "r") as file: |
There was a problem hiding this comment.
The script parses CLI args and executes file I/O at import time. Please wrap the CLI logic in a main() function and add an if __name__ == "__main__": main() guard (consistent with the other tools), so importing the module (or running static analysis) doesn’t unexpectedly run the command or call argparse.
| with open(args.filename, "r") as file: | ||
| data = yaml.safe_load(file) | ||
|
|
||
| # Sort the data by the specified key | ||
| data.sort(key=lambda x: x[args.key]) |
There was a problem hiding this comment.
yaml.safe_load() can return None (empty file) or a non-list type, and data.sort(...)/x[args.key] will raise a runtime exception (AttributeError/TypeError/KeyError) with a traceback. Please validate that the input is a list of mappings and that the sort key exists in every item, and exit with a clear error message (non-zero) if not.
| # Add the custom representer to the Dumper class | ||
| yaml.add_representer(OrderedDict, represent_ordereddict) | ||
|
|
||
| # Dump the sorted data | ||
| sorted_yaml = yaml.dump(data, default_flow_style=False) |
There was a problem hiding this comment.
This uses yaml.dump() with a custom OrderedDict representer. Prefer yaml.safe_dump() to avoid the unsafe dumper, and pass sort_keys=False so key order is preserved without needing a global representer. One option is to avoid OrderedDict entirely by constructing a normal dict with the sort key inserted first, then safe_dump(..., sort_keys=False).
| | [`git-cleanup`](git-cleanup/) | Manage GitHub Actions runs and git branches.<br>Delete all workflow runs for a branch or delete local branches except main/master. | Python | v1.0.0 | 2026-02-18 | | ||
| | [`git-copy-branch`](git-copy-branch/) | Copy file changes between git branches.<br>Copies modified/added/deleted files from origin to destination branch.<br>Auto-commits deleted files. | Python | v1.0.0 | 2026-02-18 | | ||
| | [`git-force-quit-job`](git-force-quit-job/README.md) | Force-cancel a stuck GitHub Actions run.<br>Parses the run URL and issues a force-cancel via `gh api`. | Bash | v1.0.0 | 2026-02-18 | | ||
| | [`git-update-branches`](git-update-branches/) | Batch update git repositories.<br>Iterates through a directory of repos and updates the default branch.<br>Preserves state (stash, current branch) and restores after update. | Bash | v1.0.0 | 2026-02-18 | |
There was a problem hiding this comment.
The Tools table lists the command as git-update-branches, but the repo only contains git-update-branches/git-update-branches-in-dir (no git-update-branches/git-update-branches). This also means make link won’t discover/symlink it because the Makefile only links tools where the executable name matches the directory name. Please either rename/add a wrapper executable named git-update-branches, adjust the Makefile discovery logic, or update the README entry to match the actual command name.
| | [`git-update-branches`](git-update-branches/) | Batch update git repositories.<br>Iterates through a directory of repos and updates the default branch.<br>Preserves state (stash, current branch) and restores after update. | Bash | v1.0.0 | 2026-02-18 | | |
| | [`git-update-branches-in-dir`](git-update-branches/) | Batch update git repositories.<br>Iterates through a directory of repos and updates the default branch.<br>Preserves state (stash, current branch) and restores after update. | Bash | v1.0.0 | 2026-02-18 | |
1c53721 to
275ba3b
Compare
275ba3b to
234cb2d
Compare
Summary
sort-yaml-keytool with README (was missing from repo, only existed locally)Test plan
sort-yaml-key/v1.0.0after merge