CINXE.COM

Minicli

<!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="next" href="getting_started/creating-apps/"> <link rel="icon" href="assets/images/favicon.png"> <meta name="generator" content="mkdocs-1.4.3, mkdocs-material-9.1.18"> <title>Minicli</title> <link rel="stylesheet" href="assets/stylesheets/main.26e3688c.min.css"> <link rel="stylesheet" href="assets/stylesheets/palette.ecc896b0.min.css"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"> <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style> <script>__md_scope=new URL(".",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script> <script async type="text/javascript" src="/_/static/javascript/readthedocs-addons.js"></script><meta name="readthedocs-project-slug" content="minicliphp" /><meta name="readthedocs-version-slug" content="latest" /><meta name="readthedocs-resolver-filename" content="/" /><meta name="readthedocs-http-status" content="200" /></head> <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="purple" data-md-color-accent="purple"> <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <label class="md-overlay" for="__drawer"></label> <div data-md-component="skip"> <a href="#about" class="md-skip"> Skip to content </a> </div> <div data-md-component="announce"> </div> <header class="md-header md-header--shadow" data-md-component="header"> <nav class="md-header__inner md-grid" aria-label="Header"> <a href="." title="Minicli" class="md-header__button md-logo" aria-label="Minicli" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 19V7H4v12h16m0-16a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16m-7 14v-2h5v2h-5m-3.42-4L5.57 9H8.4l3.3 3.3c.39.39.39 1.03 0 1.42L8.42 17H5.59l3.99-4Z"/></svg> </a> <label class="md-header__button md-icon" for="__drawer"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg> </label> <div class="md-header__title" data-md-component="header-title"> <div class="md-header__ellipsis"> <div class="md-header__topic"> <span class="md-ellipsis"> Minicli </span> </div> <div class="md-header__topic" data-md-component="header-topic"> <span class="md-ellipsis"> About </span> </div> </div> </div> <form class="md-header__option" data-md-component="palette"> <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="purple" data-md-color-accent="purple" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1"> <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg> </label> <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="purple" data-md-color-accent="purple" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2"> <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg> </label> </form> <label class="md-header__button md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> </label> <div class="md-search" data-md-component="search" role="dialog"> <label class="md-search__overlay" for="__search"></label> <div class="md-search__inner" role="search"> <form class="md-search__form" name="search"> <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> <label class="md-search__icon md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg> </label> <nav class="md-search__options" aria-label="Search"> <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg> </button> </nav> </form> <div class="md-search__output"> <div class="md-search__scrollwrap" data-md-scrollfix> <div class="md-search-result" data-md-component="search-result"> <div class="md-search-result__meta"> Initializing search </div> <ol class="md-search-result__list" role="presentation"></ol> </div> </div> </div> </div> </div> <div class="md-header__source"> <a href="https://github.com/minicli/minicli" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg> </div> <div class="md-source__repository"> minicli/minicli </div> </a> </div> </nav> </header> <div class="md-container" data-md-component="container"> <main class="md-main" data-md-component="main"> <div class="md-main__inner md-grid"> <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0"> <label class="md-nav__title" for="__drawer"> <a href="." title="Minicli" class="md-nav__button md-logo" aria-label="Minicli" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 19V7H4v12h16m0-16a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16m-7 14v-2h5v2h-5m-3.42-4L5.57 9H8.4l3.3 3.3c.39.39.39 1.03 0 1.42L8.42 17H5.59l3.99-4Z"/></svg> </a> Minicli </label> <div class="md-nav__source"> <a href="https://github.com/minicli/minicli" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg> </div> <div class="md-source__repository"> minicli/minicli </div> </a> </div> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item md-nav__item--active"> <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc"> <label class="md-nav__link md-nav__link--active" for="__toc"> About <span class="md-nav__icon md-icon"></span> </label> <a href="." class="md-nav__link md-nav__link--active"> About </a> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#requirements" class="md-nav__link"> Requirements </a> <nav class="md-nav" aria-label="Requirements"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#zero-dependencies" class="md-nav__link"> Zero Dependencies </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="#installation" class="md-nav__link"> Installation </a> </li> <li class="md-nav__item"> <a href="#example-code" class="md-nav__link"> Example Code </a> </li> <li class="md-nav__item"> <a href="#contributing" class="md-nav__link"> Contributing </a> </li> <li class="md-nav__item"> <a href="#history" class="md-nav__link"> History </a> <nav class="md-nav" aria-label="History"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#created-with-minicli" class="md-nav__link"> Created with Minicli </a> </li> </ul> </nav> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" > <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0"> Getting Started <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_2"> <span class="md-nav__icon md-icon"></span> Getting Started </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="getting_started/creating-apps/" class="md-nav__link"> Creating a new Minicli application </a> </li> <li class="md-nav__item"> <a href="getting_started/using-as-dependency/" class="md-nav__link"> Using Minicli in your Project </a> </li> <li class="md-nav__item"> <a href="getting_started/using-docker/" class="md-nav__link"> Running Minicli with Docker </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" > <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0"> Minicli Commands <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_3"> <span class="md-nav__icon md-icon"></span> Minicli Commands </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="getting_started/creating-controllers/" class="md-nav__link"> Creating Command Controllers </a> </li> <li class="md-nav__item"> <a href="sharing_commands/sharing-minicli-commands/" class="md-nav__link"> Sharing Minicli Commands </a> </li> <li class="md-nav__item"> <a href="the_ecosystem/commands/" class="md-nav__link"> Official Commands </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" > <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0"> Input and Output <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_4"> <span class="md-nav__icon md-icon"></span> Input and Output </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="input/input-arguments/" class="md-nav__link"> Arguments, Parameters and Flags </a> </li> <li class="md-nav__item"> <a href="input/user-input/" class="md-nav__link"> Prompting User for Input </a> </li> <li class="md-nav__item"> <a href="output/printing-output/" class="md-nav__link"> Printing Output </a> </li> <li class="md-nav__item"> <a href="output/using-themes/" class="md-nav__link"> Working with Color Themes </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" > <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0"> Advanced Usage <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_5"> <span class="md-nav__icon md-icon"></span> Advanced Usage </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="advanced/creating-services/" class="md-nav__link"> Creating and Registering Services </a> </li> <li class="md-nav__item"> <a href="advanced/config/" class="md-nav__link"> Working with confguration values </a> </li> <li class="md-nav__item"> <a href="advanced/logging/" class="md-nav__link"> Logging </a> </li> <li class="md-nav__item"> <a href="advanced/composer-bin/" class="md-nav__link"> Setting up a Minicli app as Composer bin command </a> </li> <li class="md-nav__item"> <a href="advanced/github-action/" class="md-nav__link"> Setting up a Minicli app as a GitHub Action </a> </li> <li class="md-nav__item"> <a href="advanced/minicli-runtimes/" class="md-nav__link"> Minicli OCI Runtimes </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" > <label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0"> Minicli Ecosystem <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_6"> <span class="md-nav__icon md-icon"></span> Minicli Ecosystem </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="the_ecosystem/curly/" class="md-nav__link"> minicli/curly </a> </li> <li class="md-nav__item"> <a href="the_ecosystem/stencil/" class="md-nav__link"> minicli/stencil </a> </li> <li class="md-nav__item"> <a href="the_ecosystem/minicache/" class="md-nav__link"> minicli/minicache </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" > <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0"> Tutorials <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_7"> <span class="md-nav__icon md-icon"></span> Tutorials </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="tutorials_and_demos/building-a-simple-minicli-app-with-pokemon-api/" class="md-nav__link"> How to build a simple app pulling contents from Pokemon API </a> </li> <li class="md-nav__item"> <a href="tutorials_and_demos/demos/" class="md-nav__link"> Demos </a> </li> </ul> </nav> </li> </ul> </nav> </div> </div> </div> <div class="md-content" data-md-component="content"> <article class="md-content__inner md-typeset"> <h1 id="about">About<a class="headerlink" href="#about" title="Permanent link">&para;</a></h1> <p align="center"> <img src="./images/logo/minicli_logo_term_pink.png" align="center" alt="logo" title="Minicli logo" alt="Minicli Logo" width="200"> </p> <p align="center"> <a href="//packagist.org/packages/minicli/minicli"> <img src="https://poser.pugx.org/minicli/minicli/v" alt="Latest Stable Version" title="Latest Stable Version"> </a> <a href="//packagist.org/packages/minicli/minicli"> <img src="https://poser.pugx.org/minicli/minicli/downloads" alt="Total Downloads" title="Total Downloads"> </a> <a href="//packagist.org/packages/minicli/minicli"> <img src="https://poser.pugx.org/minicli/minicli/license" alt="License" title="License"> </a> <a href="https://docs.minicli.dev/en/latest/?badge=latest"> <img src="https://readthedocs.org/projects/minicliphp/badge/?version=latest" alt="Documentation Status" title="Documentation Status"> </a> </p> <p>Minicli is a minimalist, zero-dependency framework for building CLI-centric PHP applications. It provides a structured way to organize your commands, as well as various helpers to facilitate working with command arguments, obtaining input from users, and printing colored output to the terminal. Since version 4.0, Minicli requires PHP 8.1.</p> <h2 id="requirements">Requirements<a class="headerlink" href="#requirements" title="Permanent link">&para;</a></h2> <ul> <li>PHP &gt;= 8.1</li> <li><code>ext-readline</code> to obtain user input</li> </ul> <p>Apart from that, you'll need <a href="https://getcomposer.org/">Composer</a> to install and use Minicli.</p> <h3 id="zero-dependencies">Zero Dependencies<a class="headerlink" href="#zero-dependencies" title="Permanent link">&para;</a></h3> <p>Minicli is committed to creating a safer software supply chain ecosystem, that's why we don't bring any chained dependencies with the base <code>minicli/minicli</code> package. Starting from version <code>3.2.0</code>, we also include <a href="https://en.wikipedia.org/wiki/Software_supply_chain">SBOM</a> files with every release of Minicli. You can <a href="https://github.com/minicli/minicli/releases/download/4.0.0/minicli-build.spdx.json">download here</a> our latest SBOM in SPDX format.</p> <p>The base <code>minicli/minicli</code> package contains everything you need to create a simple command-line PHP application to consume an API, generate some data, or just playing around with the command line in PHP-land. You can always opt to bootstrap your application with the <code>minicli/application</code> template repository, and you are encouraged to <a href="/sharing_commands">share and reuse Minicli commands</a>, but we believe that it should be completely up to you which packages you want your application to depend on.</p> <p>The base <code>minicli/minicli</code> package has only <strong>testing</strong> dependencies; these are only installed when you clone Minicli for development.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The <a href="https://github.com/minicli/application">minicli/application</a> project template contains the skeleton of a more structured application including tests bootstrapped with <a href="https://pestphp.com/">PestPHP</a> and a couple official Minicli commands such as the default <a href="https://github.com/minicli/command-help">help command</a>. For a dependency-free experience, you must require <code>minicli/minicli</code> from an existing project, and you'll have the freedom to create your own app structure.</p> </div> <h2 id="installation">Installation<a class="headerlink" href="#installation" title="Permanent link">&para;</a></h2> <p>There are mainly two ways to get started: you can choose to create a project from scratch, which might be a good choice for single command apps or to integrate your command / app within another system, or you can use our application repository template, which sets up a minimal structure with Command Namespaces and Controllers - this is the recommended way if you're creating a new standalone command-line application with Minicli.</p> <p>Both methods are explained in detail in the <a href="/getting_started/creating-apps/">Getting Started Guide</a>.</p> <h2 id="example-code">Example Code<a class="headerlink" href="#example-code" title="Permanent link">&para;</a></h2> <p>The following example shows a simple application with a single command registered as callback under the name <code>test</code>. The command prints output in different colors:</p> <div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">PHP</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1"> 1</a></span> <span class="normal"><a href="#__codelineno-0-2"> 2</a></span> <span class="normal"><a href="#__codelineno-0-3"> 3</a></span> <span class="normal"><a href="#__codelineno-0-4"> 4</a></span> <span class="normal"><a href="#__codelineno-0-5"> 5</a></span> <span class="normal"><a href="#__codelineno-0-6"> 6</a></span> <span class="normal"><a href="#__codelineno-0-7"> 7</a></span> <span class="normal"><a href="#__codelineno-0-8"> 8</a></span> <span class="normal"><a href="#__codelineno-0-9"> 9</a></span> <span class="normal"><a href="#__codelineno-0-10">10</a></span> <span class="normal"><a href="#__codelineno-0-11">11</a></span> <span class="normal"><a href="#__codelineno-0-12">12</a></span> <span class="normal"><a href="#__codelineno-0-13">13</a></span> <span class="normal"><a href="#__codelineno-0-14">14</a></span> <span class="normal"><a href="#__codelineno-0-15">15</a></span> <span class="normal"><a href="#__codelineno-0-16">16</a></span> <span class="normal"><a href="#__codelineno-0-17">17</a></span> <span class="normal"><a href="#__codelineno-0-18">18</a></span> <span class="normal"><a href="#__codelineno-0-19">19</a></span> <span class="normal"><a href="#__codelineno-0-20">20</a></span> <span class="normal"><a href="#__codelineno-0-21">21</a></span> <span class="normal"><a href="#__codelineno-0-22">22</a></span> <span class="normal"><a href="#__codelineno-0-23">23</a></span> <span class="normal"><a href="#__codelineno-0-24">24</a></span> <span class="normal"><a href="#__codelineno-0-25">25</a></span> <span class="normal"><a href="#__codelineno-0-26">26</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1"></a><span class="x">#!/usr/bin/php</span> <a id="__codelineno-0-2" name="__codelineno-0-2"></a><span class="cp">&lt;?php</span> <a id="__codelineno-0-3" name="__codelineno-0-3"></a> <a id="__codelineno-0-4" name="__codelineno-0-4"></a><span class="k">if</span><span class="p">(</span><span class="nb">php_sapi_name</span><span class="p">()</span> <span class="o">!==</span> <span class="s1">&#39;cli&#39;</span><span class="p">)</span> <span class="p">{</span> <a id="__codelineno-0-5" name="__codelineno-0-5"></a> <span class="k">exit</span><span class="p">;</span> <a id="__codelineno-0-6" name="__codelineno-0-6"></a><span class="p">}</span> <a id="__codelineno-0-7" name="__codelineno-0-7"></a> <a id="__codelineno-0-8" name="__codelineno-0-8"></a><span class="k">require</span> <span class="no">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/vendor/autoload.php&#39;</span><span class="p">;</span> <a id="__codelineno-0-9" name="__codelineno-0-9"></a> <a id="__codelineno-0-10" name="__codelineno-0-10"></a><span class="k">use</span> <span class="nx">Minicli\App</span><span class="p">;</span> <a id="__codelineno-0-11" name="__codelineno-0-11"></a> <a id="__codelineno-0-12" name="__codelineno-0-12"></a><span class="nv">$app</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">App</span><span class="p">([</span> <a id="__codelineno-0-13" name="__codelineno-0-13"></a> <span class="s1">&#39;app_path&#39;</span> <span class="o">=&gt;</span> <span class="p">[</span> <a id="__codelineno-0-14" name="__codelineno-0-14"></a> <span class="no">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/app/Command&#39;</span><span class="p">,</span> <a id="__codelineno-0-15" name="__codelineno-0-15"></a> <span class="p">],</span> <a id="__codelineno-0-16" name="__codelineno-0-16"></a> <span class="s1">&#39;theme&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;\Unicorn&#39;</span><span class="p">,</span> <a id="__codelineno-0-17" name="__codelineno-0-17"></a> <span class="s1">&#39;debug&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span> <a id="__codelineno-0-18" name="__codelineno-0-18"></a><span class="p">]);</span> <a id="__codelineno-0-19" name="__codelineno-0-19"></a> <a id="__codelineno-0-20" name="__codelineno-0-20"></a><span class="nv">$app</span><span class="o">-&gt;</span><span class="na">registerCommand</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">,</span> <span class="k">function</span> <span class="p">()</span> <span class="k">use</span> <span class="p">(</span><span class="nv">$app</span><span class="p">)</span> <span class="p">{</span> <a id="__codelineno-0-21" name="__codelineno-0-21"></a> <span class="nv">$app</span><span class="o">-&gt;</span><span class="na">success</span><span class="p">(</span><span class="s1">&#39;Hello World!&#39;</span> <span class="p">,</span> <span class="k">false</span><span class="p">);</span> <a id="__codelineno-0-22" name="__codelineno-0-22"></a> <span class="nv">$app</span><span class="o">-&gt;</span><span class="na">info</span><span class="p">(</span><span class="s1">&#39;With Background!&#39;</span> <span class="p">,</span> <span class="k">true</span><span class="p">);</span> <a id="__codelineno-0-23" name="__codelineno-0-23"></a> <span class="nv">$app</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span><span class="s1">&#39;Quitting!&#39;</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <a id="__codelineno-0-24" name="__codelineno-0-24"></a><span class="p">});</span> <a id="__codelineno-0-25" name="__codelineno-0-25"></a> <a id="__codelineno-0-26" name="__codelineno-0-26"></a><span class="nv">$app</span><span class="o">-&gt;</span><span class="na">runCommand</span><span class="p">(</span><span class="nv">$argv</span><span class="p">);</span> </code></pre></div></td></tr></table></div> <p>You can run the registered command with: <code>./minicli test</code>. The output looks like the following:</p> <p><img alt="image" src="images/output_index.png" title="Image of a terminal with the output of the code above." /></p> <h2 id="contributing">Contributing<a class="headerlink" href="#contributing" title="Permanent link">&para;</a></h2> <p>We welcome all types of contributions and contributors to Minicli and its adjacent repositories, as long as you stick to our <a href="https://github.com/minicli/minicli/blob/main/CODE_OF_CONDUCT.md">code of conduct</a> and follow our simple <a href="https://github.com/minicli/minicli/blob/main/CONTRIBUTING.md">contributing guidelines</a>. The TL;DR is:</p> <ul> <li>be excellent to each other</li> <li>feel free to ask all the questions</li> <li>keep simplicity always in mind</li> <li>discuss ideas before implementing something big</li> <li>follow the <a href="https://www.php-fig.org/psr/psr-12/">PSR-12</a> PHP code standards if you are contributing with code</li> </ul> <h2 id="history">History<a class="headerlink" href="#history" title="Permanent link">&para;</a></h2> <p>Minicli was initially created as an experiment about going dependency-free in the context of PHP. The following tutorials on <a href="https://dev.to/erikaheidi">dev.to</a> compose a series named "Building Minicli", where we created the first version of <code>minicli</code> from scratch:</p> <ul> <li>Part 1: <a href="https://dev.to/erikaheidi/bootstrapping-a-cli-php-application-in-vanilla-php-4ee">Bootstrapping a CLI PHP Application in Vanilla PHP</a> [ <a href="https://github.com/erikaheidi/minicli/tree/0.1.0">minicli v.0.1.0</a> ]</li> <li>Part 2: <a href="https://dev.to/erikaheidi/php-in-the-command-line-implementing-command-controllers-13lh">Building minicli: Implementing Command Controllers</a> [ <a href="https://github.com/erikaheidi/minicli/tree/0.1.2">minicli v.0.1.2</a> ]</li> <li>Part 3: <a href="https://dev.to/erikaheidi/building-minicli-autoloading-command-namespaces-3ljm">Building minicli: Autoloading Command Namespaces</a> [ <a href="https://github.com/erikaheidi/minicli/tree/0.1.3">minicli v.0.1.3</a> ]</li> <li>Part 4: <a href="https://dev.to/erikaheidi/introducing-minicli-a-microframework-for-cli-centric-php-applications-44ik">Introducing minicli: a microframework for CLI-centric PHP applications</a></li> </ul> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Minicli has evolved a lot since that series was initially written, with the help of many <a href="https://github.com/minicli/minicli/blob/main/CONTRIBUTORS.md">contributors</a>. Thank you!</p> </div> <h3 id="created-with-minicli">Created with Minicli<a class="headerlink" href="#created-with-minicli" title="Permanent link">&para;</a></h3> <p>The following applications were created using Minicli:</p> <ul> <li><a href="https://github.com/librarianphp/librarian">Librarian</a> - A minimalist file-based CMS / markdown document indexer</li> <li><a href="https://github.com/erikaheidi/dynacover">Dynacover</a> - Dynamic Twitter images and banners</li> <li><a href="https://github.com/erikaheidi/gdaisy">GDaisy</a> - <code>php-gd</code> based image templates</li> <li><a href="https://github.com/erikaheidi/minileaf">Minileaf</a> - control your Nanoleaf panels via the CLI</li> </ul> </article> </div> </div> </main> <footer class="md-footer"> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-copyright"> Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> Material for MkDocs </a> </div> </div> </div> </footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"base": ".", "features": ["navigation.sections", "toc.integrate"], "search": "assets/javascripts/workers/search.74e28a9f.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script> <script src="assets/javascripts/bundle.220ee61c.min.js"></script> <script src="readthedocs-data.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10