File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1-
21# Postal Regex 📨
32
43[ ![ PyPI version] ( https://img.shields.io/pypi/v/postal-regex.svg )] ( https://pypi.org/project/postal-regex/ )
@@ -111,6 +110,58 @@ print(df_validated)
111110
112111---
113112
113+ ## Command-Line Usage
114+
115+ You can validate postal codes directly from the command line without writing any code.
116+
117+ ### Validate Postal Codes
118+
119+ To validate one or more postal codes for a specific country:
120+
121+ ``` sh
122+ python -m postal_regex.cli validate < postal_code1> < postal_code2> ... < country>
123+ ```
124+
125+ ** Examples:**
126+
127+ Validate a single code for India:
128+ ```
129+ python -m postal_regex.cli validate 110001 IN
130+ ```
131+ Output:
132+ ```
133+ 110001: Valid
134+ ```
135+
136+ Validate multiple codes for the United States:
137+ ```
138+ python -m postal_regex.cli validate 12345 90210 US
139+ ```
140+ Output:
141+ ```
142+ 12345: Valid
143+ 90210: Valid
144+ ```
145+
146+ You can also use country names:
147+ ```
148+ python -m postal_regex.cli validate 110001 India
149+ ```
150+
151+ ### View Validation Statistics
152+
153+ To view local validation statistics:
154+ ```
155+ python -m postal_regex.cli stats
156+ ```
157+
158+ To reset statistics:
159+ ```
160+ python -m postal_regex.cli stats --reset
161+ ```
162+
163+ ---
164+
114165## Contributing
115166
116167We welcome contributions! Please see [ CONTRIBUTING.md] ( CONTRIBUTING.md ) for guidelines.
Original file line number Diff line number Diff line change 11import argparse
22from . import analytics
3+ from .core import validate
34
45
56def main ():
@@ -15,13 +16,29 @@ def main():
1516 "--reset" , action = "store_true" , help = "Reset all recorded statistics."
1617 )
1718
19+ # The 'validate' command
20+ validate_parser = subparsers .add_parser (
21+ "validate" , help = "Validate postal codes for a given country."
22+ )
23+ validate_parser .add_argument (
24+ "postal_codes" , nargs = "+" , help = "Postal code(s) to validate."
25+ )
26+ validate_parser .add_argument (
27+ "country" , help = "Country code or name to validate against."
28+ )
29+
1830 args = parser .parse_args ()
1931
2032 if args .command == "stats" :
2133 if args .reset :
2234 analytics .reset_stats ()
2335 else :
2436 analytics .show_stats ()
37+ elif args .command == "validate" :
38+ for code in args .postal_codes :
39+ is_valid = validate (args .country , code )
40+ result = "Valid" if is_valid else "Invalid"
41+ print (f"{ code } : { result } " )
2542 else :
2643 parser .print_help ()
2744
You can’t perform that action at this time.
0 commit comments