Replace magic strings with StrEnum types for command flags#86
Merged
Conversation
Define BranchSource, PrMode, and WorktreeMode as StrEnum in a new types module. Replace hardcoded string literals throughout command files with enum members. StrEnum values match the current strings, preserving JSON serialization and backward compatibility with existing persisted state.
Add clarifying comments to each flag enum value to explain their purpose and behavior. This makes the command flag types self-documenting and easier to understand without needing external references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces type-safe enums for three command flags:
branch_source,pr_mode, andworktree_mode. A newsrc/draft/types.pymodule definesBranchSource,PrMode, andWorktreeModeasStrEnumtypes. All command files are updated to use enum members instead of hardcoded string literals.The change preserves backward compatibility—enum values match current strings exactly, so existing persisted
state.jsonfiles continue to work without migration.Test plan
python -c "import json; from draft.types import BranchSource; print(json.dumps({'x': BranchSource.NEW}))"outputs{"x": "new"}BranchSource.NEW == "new"returnsTrue;"existing" in (BranchSource.NEW, BranchSource.EXISTING)returnsTruestate.jsonfrom before this change and verifyRunContext.loadfollowed by comparisons against enum members work correctlydraft createon a new branch and verifystate.jsonpersists as"new","open","worktree"(raw strings)draft create --branch <existing>and verify correct string values instate.jsondraft babysit,draft fix-pr,draft continueon existing runs and verify same expected steps as beforegh pr list --state openargument andgit worktreesubcommands)