Option C Tools
Loading...
Searching...
No Matches
oct.cli Namespace Reference

Classes

class  OctGroup

Functions

 cli (ctx, root_dir, allow_outside_project, strict_config, log_output)
 lint (ctx, args)
 format (ctx, args)
 new (ctx, path, force, test, dry_run, verbose)
 scaffold (name, dry_run, no_venv, with_claude)
 docs (ctx, sphinx_mode, doxygen_mode, all_mode, clean_mode, dry_run)
bool _pytest_missing (str combined_output)
None _run_pytest (Path project_root, tuple args, bool json_mode=False)
Path|None _map_source_to_test (Path source, Path project_root)
 test (ctx, json_mode, changed, args)
 export_source (ctx, verbose, clean, single_dir, allow_outside_project, warn_secrets, block_secrets, diff_ref, path)
 export_skeleton (ctx, json_mode, verbose, single_dir, no_diagnostics, clean, allow_outside_project, path)
 clean (ctx, path, dry_run, allow_outside_project)
 health (ctx, json_mode, verbose, test_timeout)
 deps (ctx, args)
 install_hooks_cmd (ctx, force)
 typecheck (ctx, json_mode, args)
 diag (ctx)
 diag_validate_config (ctx, bool strict)
 diag_list_domains (ctx)
 diag_set_level (ctx, domain, level, bool dry_run)
 diag_restore (ctx)
 diag_migrate_config (ctx, Path|None config_path, bool dry_run)
 install_mcp (ctx, host, dry_run)

Variables

dict _COMMAND_FLAGS
tuple _PYTEST_INSTALL_HINT
 _git_group
 name
 _migrate_group
 _audit_cmd
 _oct_install_cmd

Detailed Description

Purpose
-------
Provide the main command-line interface for the OCT (Option C Tools) ecosystem.

Responsibilities
----------------
- Define top-level commands: oct lint, oct format, oct new, oct scaffold, oct docs,
  oct test, oct export-source, oct clean, oct health.
- Delegate work to the appropriate OCT modules.
- Scaffold new Option C projects with a correct ``oc_diagnostics/debug_config.json``
  pre-configured for use with ``oc_diagnostics``.
- Set up Sphinx documentation templates in ``docs/``.
- Ensure consistent behavior across all projects.

Diagnostics
-----------
Domain: OCT-CLI
Levels:
    L2 — lifecycle
    L3 — semantic details
    L4 — deep tracing

Contracts
---------
- Must be installed as the console entry point for the OCT package.
- Must not contain business logic; only dispatching.
- Scaffolded ``debug_config.json`` must be a valid ``oc_diagnostics`` configuration.

Dependencies
------------
- oct (package version)
- oct.core.project_root (project root detection)
- oct.linter.oct_lint (linter command implementation)
- oct.formatter.oct_format (formatter command implementation)
- oct.health.oct_health (health dashboard command)
- oct.generator.new_python_file (new file scaffolding)
- oct.diag.oct_diag (diagnostics config commands)
- oct.deps.oct_deps (dependency graph command)
- oct.hooks.oct_hooks (pre-commit hooks generator)
- oct.typecheck.oct_typecheck (type-checking wrapper)
- click (CLI framework)

Function Documentation

◆ _map_source_to_test()

Path | None oct.cli._map_source_to_test ( Path source,
Path project_root )
protected
Heuristic: map a source .py file to its likely test file.

Tries several common patterns and returns the first existing match,
or ``None`` if no test file is found.

Definition at line 591 of file cli.py.

Here is the caller graph for this function:

◆ _pytest_missing()

bool oct.cli._pytest_missing ( str combined_output)
protected
Detect the 'No module named pytest' signature in combined output.

Definition at line 493 of file cli.py.

Here is the caller graph for this function:

◆ _run_pytest()

None oct.cli._run_pytest ( Path project_root,
tuple args,
bool json_mode = False )
protected
Run pytest in *project_root* and exit on failure.

When *json_mode* is True, captures pytest output, parses the summary
line, and emits a machine-readable JSON object to stdout:
``{"tool": "test", "passed": N, "failed": N, "errors": N,
   "warnings": N, "output": "...", "exit_code": N}``

OI-511: pytest is now declared in the ``[project.optional-dependencies].test``
extra rather than as a runtime dependency; if ``python -m pytest`` reports
it is not importable, emit the install hint above and exit 1.

Definition at line 498 of file cli.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean()

oct.cli.clean ( ctx,
path,
dry_run,
allow_outside_project )
Remove _source_code-*, _skeleton_code-* export dirs and __pycache__ dirs.

Definition at line 839 of file cli.py.

◆ cli()

oct.cli.cli ( ctx,
root_dir,
allow_outside_project,
strict_config,
log_output )
OCT — Option C Tools

Definition at line 335 of file cli.py.

◆ deps()

oct.cli.deps ( ctx,
args )
Analyse inter-module dependencies.

Definition at line 889 of file cli.py.

◆ diag()

oct.cli.diag ( ctx)
oc_diagnostics configuration tools.

Definition at line 951 of file cli.py.

◆ diag_list_domains()

oct.cli.diag_list_domains ( ctx)
List configured domains with their levels and colors.

Definition at line 986 of file cli.py.

◆ diag_migrate_config()

oct.cli.diag_migrate_config ( ctx,
Path | None config_path,
bool dry_run )
OI-508 / FS-515: upgrade a legacy v1 debug_config.json to v2.0.

When PATH is omitted, migrates the project's own debug_config.json.
Writes ``<path>.bk`` before overwriting; idempotent — running twice
over an already-v2 file is a no-op.

Definition at line 1061 of file cli.py.

◆ diag_restore()

oct.cli.diag_restore ( ctx)
OI-528: restore debug_config.json from its .bk backup.

Definition at line 1038 of file cli.py.

◆ diag_set_level()

oct.cli.diag_set_level ( ctx,
domain,
level,
bool dry_run )
Set a domain's debug level (0-4).

OI-528: the write is always preceded by a ``<path>.bk`` backup so
``oct diag restore`` can undo a bad edit. ``--dry-run`` prints the
would-be post-edit config to stdout and skips both writes.

Definition at line 1014 of file cli.py.

◆ diag_validate_config()

oct.cli.diag_validate_config ( ctx,
bool strict )
Validate debug_config.json against the expected schema.

Definition at line 964 of file cli.py.

◆ docs()

oct.cli.docs ( ctx,
sphinx_mode,
doxygen_mode,
all_mode,
clean_mode,
dry_run )
Validate or build Option C documentation.

Definition at line 431 of file cli.py.

◆ export_skeleton()

oct.cli.export_skeleton ( ctx,
json_mode,
verbose,
single_dir,
no_diagnostics,
clean,
allow_outside_project,
path )
Export structural skeletons of source files for AI inspection.

Definition at line 799 of file cli.py.

◆ export_source()

oct.cli.export_source ( ctx,
verbose,
clean,
single_dir,
allow_outside_project,
warn_secrets,
block_secrets,
diff_ref,
path )
Export consolidated source-code files for inspection.

Definition at line 737 of file cli.py.

◆ format()

oct.cli.format ( ctx,
args )
Auto-fix Option C compliance violations in Python files.

Definition at line 366 of file cli.py.

◆ health()

oct.cli.health ( ctx,
json_mode,
verbose,
test_timeout )
Display project compliance dashboard.

Definition at line 874 of file cli.py.

◆ install_hooks_cmd()

oct.cli.install_hooks_cmd ( ctx,
force )
[DEPRECATED] Use 'oct git hooks install' instead.

Definition at line 900 of file cli.py.

◆ install_mcp()

oct.cli.install_mcp ( ctx,
host,
dry_run )
Install oct-mcp into an AI host's MCP config (Claude Code, Cursor, VS Code).

Definition at line 1098 of file cli.py.

◆ lint()

oct.cli.lint ( ctx,
args )
Run the Option C linter.

Definition at line 355 of file cli.py.

◆ new()

oct.cli.new ( ctx,
path,
force,
test,
dry_run,
verbose )
Create a new Option C-compliant Python file.

Definition at line 379 of file cli.py.

◆ scaffold()

oct.cli.scaffold ( name,
dry_run,
no_venv,
with_claude )
Create a new Option C project.

Definition at line 393 of file cli.py.

◆ test()

oct.cli.test ( ctx,
json_mode,
changed,
args )
Run the project's test suite.

Definition at line 633 of file cli.py.

Here is the call graph for this function:

◆ typecheck()

oct.cli.typecheck ( ctx,
json_mode,
args )
Run type checking (pyright or mypy).

Definition at line 924 of file cli.py.

Variable Documentation

◆ _audit_cmd

oct.cli._audit_cmd
protected

Definition at line 942 of file cli.py.

◆ _COMMAND_FLAGS

dict oct.cli._COMMAND_FLAGS
protected

Definition at line 72 of file cli.py.

◆ _git_group

oct.cli._git_group
protected

Definition at line 934 of file cli.py.

◆ _migrate_group

oct.cli._migrate_group
protected

Definition at line 938 of file cli.py.

◆ _oct_install_cmd

oct.cli._oct_install_cmd
protected

Definition at line 946 of file cli.py.

◆ _PYTEST_INSTALL_HINT

tuple oct.cli._PYTEST_INSTALL_HINT
protected
Initial value:
1= (
2 "pytest is not installed. Install it with one of:\n"
3 " pip install oct[test] # installs OCT's test extras\n"
4 " pip install pytest # install pytest directly"
5)

Definition at line 486 of file cli.py.

◆ name

oct.cli.name

Definition at line 934 of file cli.py.