Cli Utils
Utility functions for CLI operations in CodeMap.
console
module-attribute
console = Console()
logger
module-attribute
logger = getLogger(__name__)
ProgressUpdater
module-attribute
ProgressUpdater = Callable[
[str | None, int | None, int | None], None
]
SpinnerState
Singleton class to manage the stack and display of active spinners.
Source code in src/codemap/utils/cli_utils.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
spinner_message_stack
instance-attribute
spinner_message_stack: list[str]
active_rich_status_cm
instance-attribute
active_rich_status_cm: Status | None
tree_display_active
class-attribute
instance-attribute
tree_display_active: bool = False
__new__
__new__() -> Self
Create or return the singleton instance.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The singleton instance of SpinnerState |
Source code in src/codemap/utils/cli_utils.py
44 45 46 47 48 49 50 51 52 53 54 55 |
|
start_new_spinner
start_new_spinner(message: str) -> None
Handles the start of a new spinner.
Adds the new spinner message to the stack and updates the tree display.
Source code in src/codemap/utils/cli_utils.py
128 129 130 131 132 133 134 |
|
stop_current_spinner_and_resume_parent
stop_current_spinner_and_resume_parent() -> None
Handles the end of the current spinner.
Pops the top spinner from the stack and updates the tree display.
Source code in src/codemap/utils/cli_utils.py
136 137 138 139 140 141 142 143 144 145 146 147 |
|
temporarily_halt_visual_spinner
temporarily_halt_visual_spinner() -> bool
Stops the current visual spinner if one is active.
Used when a progress bar is about to take over. Returns True if a visual spinner was halted, False otherwise.
Source code in src/codemap/utils/cli_utils.py
149 150 151 152 153 154 155 156 157 158 |
|
resume_visual_spinner_if_needed
resume_visual_spinner_if_needed() -> None
Resumes a visual spinner for the top message on the stack.
If the stack is not empty and no visual spinner is currently active. Used after a progress bar (that might have halted a spinner) finishes.
Source code in src/codemap/utils/cli_utils.py
160 161 162 163 164 165 166 167 |
|
progress_indicator
progress_indicator(
message: str,
style: Literal["spinner", "progress"] = "spinner",
total: int | None = None,
transient: bool = False,
) -> Iterator[ProgressUpdater]
Standardized progress indicator that supports different styles uniformly.
Manages nested spinners and interaction between spinners and progress bars to prevent UI flickering and ensure a clear display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message to display with the progress indicator. |
required |
style
|
Literal['spinner', 'progress']
|
The style of progress indicator ('spinner' or 'progress'). |
'spinner'
|
total
|
int | None
|
For determinate progress, the total units of work. |
None
|
transient
|
bool
|
Whether the progress indicator should disappear after completion. |
False
|
Yields:
Type | Description |
---|---|
ProgressUpdater
|
A callable (ProgressUpdater) for updating the progress/spinner. |
ProgressUpdater
|
For spinners, the callable is a no-op accepting three ignored arguments. |
ProgressUpdater
|
For progress bars, it accepts description, completed, and total (all optional). |
Source code in src/codemap/utils/cli_utils.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
exit_with_error
exit_with_error(
message: str,
exit_code: int = 1,
exception: Exception | None = None,
) -> None
Display an error message and exit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
Error message to display |
required |
exit_code
|
int
|
Exit code to use |
1
|
exception
|
Exception | None
|
Optional exception that caused the error |
None
|
Source code in src/codemap/utils/cli_utils.py
236 237 238 239 240 241 242 243 244 245 246 247 |
|
handle_keyboard_interrupt
handle_keyboard_interrupt() -> None
Handles KeyboardInterrupt by printing a message and exiting cleanly.
Source code in src/codemap/utils/cli_utils.py
250 251 252 253 |
|
check_for_updates
check_for_updates(is_verbose_param: bool) -> None
Check PyPI for a new version of CodeMap and warn if available.
Source code in src/codemap/utils/cli_utils.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|