n98-magerun2 Documentation

website·Indexed 30 days ago

https://netz98.github.io/n98-magerun2

A command-line tool for Magento 2 that provides a wide range of utilities for development and administration. The documentation covers installation via Phar or Composer, general usage, scripting features, and extending the tool through custom Symfony2 commands, modules, and configuration aliases.

Tokens
45.3K
Snippets
293
Records
386
Agent score
75%

What's inside n98-magerun2

  1. Overview of n98-magerun2 command namespaces

    n98-magerun2 organizes its commands into namespaces based on functionality. Common namespaces include:

    • admin: Manage Magento admin users and settings (e.g., admin:user:list, admin:user:create).
    • cache: Manage Magento cache systems (e.g., cache:clean, cache:flush).
    • config: Manage store configurations and environment settings (e.g., config:store:get, config:env:set).
    • customer: Manage customer accounts (e.g., customer:create, customer:list).
    • db: Database operations (e.g., db:dump, db:import, db:query).
    • dev: Developer tools, code generation, and debugging (e.g., dev:module:create, dev:console).
    • eav: Manage Entity-Attribute-Value attributes (e.g., eav:attribute:list).
    • generation: Code generation processes (e.g., generation:flush).
    • giftcard: Manage gift cards (e.g., giftcard:create, giftcard:info).
    • index: Manage indexers (e.g., indexer:list, indexer:trigger:recreate).
    • install: Install Magento (install).
    • integration: Manage Magento integrations (e.g., integration:list, integration:delete).
    • mageforge: Install and manage the MageForge tool (mageforge:install).
    • magerun: n98-magerun2 internal configuration and tools (e.g., magerun:config:info).
    • mcp: Model Context Protocol (MCP) server integration (mcp:server:start).
    • routes: View and manage Magento routes (routes:list).
    • script: Run sequences of commands from a file (script).
    • sys: System-level info, maintenance, and checks (e.g., sys:info, sys:cron:list).
  2. Overview of n98-magerun2

    n98-magerun2 is a command-line tool designed for developers, system administrators, and DevOps professionals working with Adobe Commerce, Magento, and Mage-OS. It provides a set of commands to automate repetitive tasks, manage system configurations, and perform maintenance without using the admin panel. Note: This version is for modern Magento-based platforms; for Magento 1 or OpenMage, use the original n98-magerun.
  3. Understand the n98-magerun2 internal configuration loading process

    n98-magerun2 uses a layered configuration system where settings are loaded and merged from multiple sources. The process is orchestrated by the N98\Magento\Application class during its init() method and occurs in two primary stages:

    1. Partial Config Load (Stage One): Config::loadPartialConfig() is called to load basic configuration files (dist, system, user) to establish initial settings and command aliases.
    2. Magento Detection: The application detects the Magento root directory, which determines the location of project-specific configurations.
    3. Full Config Load (Stage Two): ConfigurationLoader::loadStageTwo() loads additional files, such as project and stop-file configs, using the discovered Magento root.

    Configuration Merging Order: Files are merged in the following order, with later files overriding earlier ones:

    1. Dist (default)
    2. System
    3. User
    4. Plugin
    5. Project
    6. Stop-file (if present)
  4. Use github:pr to manage GitHub Pull Requests

    The github:pr command in n98-magerun2 allows developers to retrieve information about GitHub Pull Requests, download patches, apply patches, and view diffs directly from the CLI.
    n98-magerun2 github:pr
  5. Use AGENTS.md for AI assistant project context

    The AGENTS.md file at the repository root serves as the tool-agnostic source of truth for AI coding assistants (such as Claude Code and OpenCode). It provides the assistant with essential project guardrails, including build, test, and static analysis commands, project structure (e.g., src/N98/..., tests/..., docs/...), guidelines for adding new commands, and branch naming/Conventional Commits rules. When project conventions change, AGENTS.md should be updated first to ensure assistant-generated contributions remain consistent.
  6. Automate n98-magerun2 tasks using script files

    n98-magerun2 provides scripting capabilities to automate repetitive tasks by executing a sequence of multiple commands defined within a script file. The primary command for this functionality is script.
  7. n98-magerun2 Operating System support and limitations

    n98-magerun2 is automatically tested and supported on various Linux distributions and macOS. Microsoft Windows is not fully supported; specifically, certain commands such as db:dump and install are unavailable on Windows.
  8. List all registered API routes in Magento 2

    Use the routes:api:list command to get an overview of all available API endpoints, their corresponding HTTP methods, and the service classes (handlers) that process them. This is specifically for Magento 2 installations and requires a successfully initialized application to function. The output includes the area (typically webapi), the route path, the HTTP method, and the handler class/method.
    n98-magerun2 routes:api:list [options]
  9. Manage Magento routing information with n98-magerun2

    n98-magerun2 provides a set of commands to view and manage Magento's routing information. The available commands in this category include routes:list for listing general routes and routes:api:list for listing API-specific routes.
  10. Retrieve GitHub Pull Request information using n98-magerun2

    The github:pr command fetches information about a specific GitHub Pull Request. By default, it targets the magento/magento2 repository. To avoid GitHub API rate limits for unauthenticated users, provide a GitHub token via the --github-token option or set the GITHUB_TOKEN environment variable.
    # For Magento 2 Open Source
    n98-magerun2.phar github:pr <number>
    
    # For Mage-OS
    n98-magerun2.phar github:pr --mage-os <number>
  11. Retrieve Magento database configuration using db:info

    The db:info command dumps information about the current database configuration defined in app/etc/env.php. It is used for debugging and environment checks, and can provide connection strings for JDBC and PDO connections. You can either print all database information or target a specific setting by providing it as an argument.
    # Print all database information
    n98-magerun2.phar db:info
    
    # Print only the value of a specific named setting
    n98-magerun2.phar db:info <setting>