Service Command API Reference¶
This section documents the internals of the service
command in Bijux CLI.
bijux_cli.commands.history.service ¶
Implements the history
command for the Bijux CLI.
This module provides functionality to interact with the persistent command history. It allows for listing, filtering, sorting, grouping, importing, and exporting history entries. All operations produce structured, machine-readable output.
The command has three primary modes of operation: 1. Listing (Default): When no import/export flags are used, it lists history entries, which can be filtered, sorted, and grouped. 2. Import: The --import
flag replaces the current history with data from a specified JSON file. 3. Export: The --export
flag writes the entire current history to a specified JSON file.
Output Contract
- List Success:
{"entries": list}
- Import Success:
{"status": "imported", "file": str}
- Export Success:
{"status": "exported", "file": str}
- Verbose: Adds
{"python": str, "platform": str}
to the payload. - Error:
{"error": str, "code": int}
Exit Codes
0
: Success.1
: A fatal error occurred (e.g., history service unavailable).2
: An invalid argument was provided or an I/O error occurred during import/export.
history ¶
history(
ctx: Context,
limit: int = Option(
20,
"--limit",
"-l",
help="Maximum number of entries (0 means none).",
),
group_by: str | None = Option(
None,
"--group-by",
"-g",
help="Group entries by a field (e.g., 'command').",
),
filter_cmd: str | None = Option(
None,
"--filter",
"-F",
help="Return only entries whose command contains TEXT.",
),
sort: str | None = Option(
None,
"--sort",
help="Sort key; currently only 'timestamp' is recognized.",
),
export_path: str = Option(
None,
"--export",
help="Write entire history to FILE (JSON). Overwrites.",
),
import_path: str = Option(
None,
"--import",
help="Load history from FILE (JSON), replacing current store.",
),
quiet: bool = Option(
False, "-q", "--quiet", help=HELP_QUIET
),
verbose: bool = Option(
False, "-v", "--verbose", help=HELP_VERBOSE
),
fmt: str = Option(
"json", "-f", "--format", help=HELP_FORMAT
),
pretty: bool = Option(
True, "--pretty/--no-pretty", help=HELP_NO_PRETTY
),
debug: bool = Option(
False, "-d", "--debug", help=HELP_DEBUG
),
) -> None
Lists, imports, or exports the command history.
This function orchestrates all history-related operations. It first checks for an import or export action. If neither is specified, it proceeds to list the history, applying any specified filtering, grouping, or sorting.
Parameters:
-
ctx
(Context
) –The Typer context for the CLI.
-
limit
(int
, default:Option(20, '--limit', '-l', help='Maximum number of entries (0 means none).')
) –The maximum number of entries to return for a list operation.
-
group_by
(str | None
, default:Option(None, '--group-by', '-g', help="Group entries by a field (e.g., 'command').")
) –The field to group history entries by ('command').
-
filter_cmd
(str | None
, default:Option(None, '--filter', '-F', help='Return only entries whose command contains TEXT.')
) –A substring to filter command names by.
-
sort
(str | None
, default:Option(None, '--sort', help="Sort key; currently only 'timestamp' is recognized.")
) –The key to sort entries by ('timestamp').
-
export_path
(str
, default:Option(None, '--export', help='Write entire history to FILE (JSON). Overwrites.')
) –The path to export history to. This is an exclusive action.
-
import_path
(str
, default:Option(None, '--import', help='Load history from FILE (JSON), replacing current store.')
) –The path to import history from. This is an exclusive action.
-
quiet
(bool
, default:Option(False, '-q', '--quiet', help=HELP_QUIET)
) –If True, suppresses all output except for errors.
-
verbose
(bool
, default:Option(False, '-v', '--verbose', help=HELP_VERBOSE)
) –If True, includes Python/platform details in the output.
-
fmt
(str
, default:Option('json', '-f', '--format', help=HELP_FORMAT)
) –The output format ("json" or "yaml").
-
pretty
(bool
, default:Option(True, '--pretty/--no-pretty', help=HELP_NO_PRETTY)
) –If True, pretty-prints the output.
-
debug
(bool
, default:Option(False, '-d', '--debug', help=HELP_DEBUG)
) –If True, enables debug diagnostics.
Returns:
-
None
(None
) –
Raises:
-
SystemExit
–Always exits with a contract-compliant status code and payload upon completion or error.
Source code in src/bijux_cli/commands/history/service.py
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 168 169 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
resolve_history_service ¶
resolve_history_service(
command: str,
fmt_lower: str,
quiet: bool,
include_runtime: bool,
debug: bool,
) -> HistoryProtocol
Resolves the HistoryProtocol implementation from the DI container.
Parameters:
-
command
(str
) –The full command name (e.g., "history").
-
fmt_lower
(str
) –The chosen output format, lowercased.
-
quiet
(bool
) –If True, suppresses non-error output.
-
include_runtime
(bool
) –If True, includes runtime metadata in errors.
-
debug
(bool
) –If True, enables debug diagnostics.
Returns:
-
HistoryProtocol
(HistoryProtocol
) –An instance of the history service.
Raises:
-
SystemExit
–Exits with a structured error if the service cannot be resolved from the container.