Bake - run bash bash

    I think many people know the situation when own invented bicycle is not used anywhere later. Therefore, I did not dare to publish this development for a long time, until I noticed that I was dragging it from project to project. And so, one of the essential elements of modern development are the so-called task runners - these are Grunt / Gulp for nodejs, Rake for Ruby, Make for C / C ++, etc. And for the main developer tool - the console - there is nothing like that. More precisely, there is, but, as is usually the case, not quite that. As a result of the research, the Bake tool, a bash scriptr written with the support of a modular structure, was born.


    Key Features:


    • Taska as a function.
    • Argument support.
    • Modules

    Purpose


    Bake is well suited for automating routine actions, such as starting / restarting necessary services, clearing the cache, creating a directory structure, executing commands for ssh / sftp (for example, for loading configuration data and setting the correct access rights).


    The tool is extremely easy to use; all you need is to add task functions to it bake.shand you can call them from the command line:


    bake[OPTIONS] <TASK> [TASK_ARGS]

    Bake file


    Tasks are stored in a file bake.sh. Bake will search for this file in the current directory, if not, then in the parent, up to the root of the system. The directory where the bake.shproject root is located is assigned to a variable $PWD. Accordingly, all tasks are performed relative to the root, and not the current directory, which is stored in a variable $CWD.


    Taski


    Tasks are functions whose name begins with task:. Example:


    task:greet() {
        echo"Hello World"
    }

    Call from console:


    bake greet # -> Hello World

    Attention! Hyphens in the name of a task are replaced with underscores. Tasks task:hello_worldcan be called with the bake hello-worldand commands bake hello_world.


    Arguments


    The arguments following the task name are passed to the function:


    task:greet() {
        echo"Hello $1"
    }

    bake greet World # -> Hello World

    Modules


    Bake allows you to divide the code into modules and connect them as needed. Modules are stored in the bake_modules directory as scripts, for example ssh.sh. Connect modules using the command bake:module <name>. Example:


    bake:module ssh # include "bake_modules/ssh.sh"
    bake:module mysql # include "bake_modules/mysql.sh"

    Like Node.js, Bake searches for modules along the ascending path in directories bake_modulesup to the root of the system. For example, if the current path of the project /home/user/projects/my-app, the module will be consistently searched in directories:


    /home/user/projects/my-app/bake_modules
    /home/user/projects/bake_modules
    /home/user/bake_modules
    /home/bake_modules
    /bake_modules

    Installation


    • Deb package for ubuntu:
      wget https://github.com/rumkin/bake/releases/download/v0.12.5/bake_0.12-5.deb
      sudo dpkg -i bake_012-5.deb
    • Install from source code on github:
          git clone https://github.com/rumkin/bake
          sudo cp bake/bake.sh /usr/bin/bake

    Links



    Also popular now: