Skip to content

Latest commit

Β 

History

History
104 lines (80 loc) Β· 3.76 KB

File metadata and controls

104 lines (80 loc) Β· 3.76 KB

cisco_parser

Cisco IOS communications and configuration parsing library. PHP >= 7.4, PSR-4, PHPUnit.

Commands

composer install
vendor/bin/phpunit tests/ -v
vendor/bin/phpunit tests/ -v --coverage-clover coverage.xml --whitelist src/

Architecture

  • Namespace: Detain\CiscoParser\ β†’ src/
  • Core: src/CiscoParser.php β€” recursive config parser (parse_cisco_children, get_space_depth)
  • Loader: src/CiscoLoader.php β€” connection/communication layer (SSH/telnet via ext-ssh2)
  • CLI: bin/cisco_parser.php β€” reads a config file, invokes parse_cisco_children
  • Tests: tests/ciscoTest.php extends PHPUnit\Framework\TestCase
  • CI: .scrutinizer.yml Β· .travis.yml Β· coverage via clover to coverage.xml
  • IDE: .idea/ β€” PhpStorm project configuration (inspectionProfiles/, cisco_parser.iml, deployment.xml)

Conventions

  • Tabs for indentation (see .scrutinizer.yml use_tabs: true)
  • camelCase properties and parameters; UPPER_CASE constants
  • One class per file; no closing ?>
  • PHPDoc on all public methods (@param, @return required)
  • Tests: extend PHPUnit\Framework\TestCase; bootstrap via Composer autoloader
  • parse_cisco_children(array $lines, int $x, int $depth) returns nested ['command', 'arguments'?, 'children'?] arrays
  • get_space_depth(array $lines, int $x) returns leading-space count as depth

Coding Patterns

namespace Detain\CiscoParser;

class CiscoParser {
	public function myMethod(array $lines, $x = 0) {
		// use mb_strlen / mb_substr / mb_strpos for multibyte safety
		$depth = $this->get_space_depth($lines, $x);
		$command = ltrim($lines[$x]);
		return [];
	}
}
// tests/ciscoTest.php pattern
use PHPUnit\Framework\TestCase;
class myFeatureTest extends TestCase {
	protected function setUp() {
		$this->object = new \Detain\CiscoParser\CiscoParser();
	}
	public function testMyMethod() {
		$this->assertEquals($expected, $this->object->myMethod($lines));
	}
}
# run single test
vendor/bin/phpunit tests/ciscoTest.php --filter testMyMethod -v

Notes

  • ext-ssh2 is suggested, not required; guard SSH calls with extension_loaded('ssh2')
  • Commit messages: lowercase, descriptive (fix depth parsing, add vlan parser)

Before Committing

Run caliber refresh before creating git commits to keep docs in sync with code changes. After it completes, stage any modified doc files before committing:

caliber refresh && git add CLAUDE.md .claude/ .cursor/ .github/copilot-instructions.md AGENTS.md CALIBER_LEARNINGS.md 2>/dev/null

Session Learnings

Read CALIBER_LEARNINGS.md for patterns and anti-patterns learned from previous sessions. These are auto-extracted from real tool usage β€” treat them as project-specific rules.

Model Configuration

Recommended default: claude-sonnet-4-6 with high effort (stronger reasoning; higher cost and latency than smaller models). Smaller/faster models trade quality for speed and cost β€” pick what fits the task. Pin your choice (/model in Claude Code, or CALIBER_MODEL when using Caliber with an API provider) so upstream default changes do not silently change behavior.

Context Sync

This project uses Caliber to keep AI agent configs in sync across Claude Code, Cursor, Copilot, and Codex. Configs update automatically before each commit via caliber refresh. If the pre-commit hook is not set up, run /setup-caliber to configure everything automatically.