Skip to content

Commit c347b26

Browse files
Exit Message (#101)
* fix : CLI modified * feat : EXIT_MESSAGE added * doc : pragma: no cover * fix : autopep8 * doc : CHANGELOG.md updated * fix : minor issue in main fixed
1 parent 3bc553a commit c347b26

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- CLI messages updated
10+
- CLI modified
811
## [0.8] - 2026-02-05
912
### Added
1013
- Support [wtfismyip.com](https://wtfismyip.com/json) IPv6 API

ipspot/cli.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .params import IPSPOT_OVERVIEW, IPSPOT_REPO, IPSPOT_VERSION
1111
from .params import PUBLIC_IPV4_ERROR, PRIVATE_IPV4_ERROR
1212
from .params import PUBLIC_IPV6_ERROR, PRIVATE_IPV6_ERROR
13+
from .params import EXIT_MESSAGE
1314

1415

1516
def _print_ipspot_info() -> None: # pragma: no cover
@@ -93,8 +94,8 @@ def _print_report(ipv4_api: IPv4API,
9394
print(" Error: {public_ipv6_result}".format(public_ipv6_result=PUBLIC_IPV6_ERROR))
9495

9596

96-
def main() -> None: # pragma: no cover
97-
"""CLI main function."""
97+
def _parse_args() -> argparse.Namespace: # pragma: no cover
98+
"""Parse arguments."""
9899
parser = argparse.ArgumentParser()
99100
parser.add_argument(
100101
'--ipv4-api',
@@ -117,8 +118,16 @@ def main() -> None: # pragma: no cover
117118
parser.add_argument('--max-retries', help='number of retries', type=int, default=0)
118119
parser.add_argument('--retry-delay', help='delay between retries (in seconds)', type=float, default=1.0)
119120
parser.add_argument('--backoff-factor', help='backoff factor', type=float, default=1.0)
120-
121121
args = parser.parse_args()
122+
return args
123+
124+
125+
def _run(args: argparse.Namespace) -> None: # pragma: no cover
126+
"""
127+
Run ipspot CLI.
128+
129+
:param args: arguments
130+
"""
122131
if args.version:
123132
print(IPSPOT_VERSION)
124133
elif args.info:
@@ -135,3 +144,12 @@ def main() -> None: # pragma: no cover
135144
max_retries=args.max_retries,
136145
retry_delay=args.retry_delay,
137146
backoff_factor=args.backoff_factor)
147+
148+
149+
def main() -> None: # pragma: no cover
150+
"""CLI main function."""
151+
try:
152+
args = _parse_args()
153+
_run(args)
154+
except (KeyboardInterrupt, EOFError):
155+
print(EXIT_MESSAGE)

ipspot/params.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ class IPv6API(Enum):
7777
PRIVATE_IPV4_ERROR = "Unable to retrieve private IPv4 address."
7878
PUBLIC_IPV6_ERROR = "Unable to retrieve public IPv6 information."
7979
PRIVATE_IPV6_ERROR = "Unable to retrieve private IPv6 address."
80+
81+
EXIT_MESSAGE = "See you. Bye!"

0 commit comments

Comments
 (0)