Improve value argument to accept hex, binary, and octal literals (#4)#5
Open
p0dalirius wants to merge 1 commit intomainfrom
Open
Improve value argument to accept hex, binary, and octal literals (#4)#5p0dalirius wants to merge 1 commit intomainfrom
p0dalirius wants to merge 1 commit intomainfrom
Conversation
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.
Linked Issue
Closes #4
Motivation
userAccountControlandsAMAccountTypeare almost always displayed in hexadecimal in Windows/AD tooling and Microsoft documentation (e.g.0x200,0x30000001). The decoder previously accepted decimal only, forcing users to convert before running it. This change removes that friction by letting the CLI consume any standard Python integer literal.What Changed
int(options.value)withint(options.value, 0)and centralised the parse in a single try/except at the top of the__main__block.int(x, 0)auto-detects the base from the0x/0b/0o/ no-prefix form.options.value = int(options.value)lines that are now redundant.[!] Invalid value <repr>: expected an integer (decimal, 0x… hex, 0b… binary, or 0o… octal)and exits with status code1, instead of crashing with aValueErrortraceback.README.mddocumenting that hex/binary/octal values are accepted.Design Notes
int(x, 0)is a superset ofint(x)for every previously accepted value — plain decimal digits still parse the same way. No change to the decoding logic itself was required. The friendly error path also covers the crash seen in #2; this PR and the PR against #2 touch the same region, so whichever lands first will make the other a trivial rebase.Acceptance Criteria Check
./msFlagsDecoder.py userAccountControl 0x200matches./msFlagsDecoder.py userAccountControl 512— verified below../msFlagsDecoder.py sAMAccountType 0x30000000matches./msFlagsDecoder.py sAMAccountType 805306368— verified below../msFlagsDecoder.py userAccountControl 0b1000000000matches./msFlagsDecoder.py userAccountControl 512— verified below.abc/0xZZproduce a concise error message and non-zero exit status — verified below.README.md.How Verified
Runtime:
Test Coverage
None: repository has no automated test suite; behaviour is verified via the runtime checks above. Adding a test harness is out of scope for this enhancement.
Scope of Change
msFlagsDecoder.py,README.mdRisk and Rollout
Local change limited to the CLI entry point and the usage note in the README. No existing input regresses. Safe to merge without staged rollout.
Notes
Overlaps with issue #2 / PR #3: both sit on the same three lines. Merging either one first makes the other a trivial rebase.