Code Monkey home page Code Monkey logo

application's Introduction

minicli

Minicli is an experimental dependency-free toolkit for building CLI-only applications in PHP created by @erikaheidi. This repository is a template you can use to create a new application that has a single dependency: minicli/minicli.

Why minicli

The current trend in software development is basing your project on a big pile of unknowns. There is nothing wrong in using third party software, but if more than 80% of your application is out of your control, things can get messy. What usually happens is that you don't even know what packages you're depending on, when using the most popular frameworks.

Minicli was created as an educational experiment and a way to go dependency-free when building simple command-line applications in PHP. It can be used for microservices, personal dev tools, bots and little fun things.

Getting Started

You'll need php-cli and Composer to get started.

Create a new project with:

composer create-project --prefer-dist minicli/application myapp

Once the installation is finished, you can run minicli it with:

cd myapp
./minicli

This will show you the default app signature:

usage: ./minicli help

The default help command that comes with minicli (app/Command/Help/DefaultController.php) auto-generates a tree of available commands:

./minicli help
Available Commands

help
└──test

The help test command, defined in app/Command/Help/TestController.php, shows an echo test of parameters:

./minicli help test user=erika name=value
Hello, erika!

Array
(
    [user] => erika
    [name] => value
)

The simplest app

The simplest minicli script doesn't require using Command Controllers at all. You can delete the app folder and use registerCommand with an anonymous function, like this:

#!/usr/bin/php
<?php

if (php_sapi_name() !== 'cli') {
    exit;
}

require __DIR__ . '/vendor/autoload.php';

use Minicli\App;
use Minicli\Command\CommandCall;

$app = new App();
$app->setSignature('./minicli mycommand');

$app->registerCommand('mycommand', function(CommandCall $input) {
    echo "My Command!";

    var_dump($input);
});

$app->runCommand($argv);

Created with Minicli

  • Dolphin - a CLI tool for managing DigitalOcean servers with Ansible.

application's People

Contributors

erikaheidi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.