Twister: A Simple Way to Manage Your Scripts

Imagine an average project that has many scripts, each written using different practices, uses different argument names, different namings, does something similar to other script but a bit different etc. Sometimes there are so many scripts, that it's hard to find the one you really need at this very moment. Moreover, scripts have no standard location, often put in semi-random directories, so it's really hard to find them. And even more, many developers have similar scripts for different projects. Some scripts are in the PATH, others are relative to the project directory. The one in the PATH are named in odd manner, because different versions used for different projects. And some scripts are written using bash and ruby and python etc.

Oh, so many troubles just because of the scripts. That's the reason why Twister was created. Twister is a simple framework/tool that allows to create and manage project scripts. I use it in a few of my home projects, and find it very helpful. About a year ago, I open sourced Twister. It's a python project, so it makes it simple to create scripts and execute them on any popular operating system.

 Twister helps to achieve next goals:
  1. Structure project scripts into groups (known as modules).
  2. Separate scripts from different projects by having different twister setups and aliases
  3. Simple and single structure to create scripts. As result, also a single place for all project scripts.
  4. Set of built-it commands to enumerate commands, find interested command and see its description
Each script or, in terms of twister, command belongs to some module. Module consists of one or more scripts. To execute the specific script, one need also to specify the name of the module. For example, there is a need to run a command build from module dev. This can be done as simple as:
twister dev build
In case the command is used often, it's possible to create an alias for it. For example, for dev build there could be added alias bld, so previous command shorts to:
twister bld
Built-in commands does not require any module name.

Twister should be setup separately for each project. I usually put twister directory into the same Git repository. I add modules and scripts to the project's twister setup then. Thus, I keep twister and my scripts in the version control. Which is very convenient. After than, I use the add-shortcut command to create a shortcut in PATH to the project's twister. As I have multiple twister setups, I use project name instead of twister. For example, let I have a project name colibri. There is a separate twister setup for it, with custom build script. My first move is to setup a shortcut to colibri's twister:
./twister.py add-shortcut --name colibri
This will create a soft-link to the local twister setup, will name this link colibri and will place it into /usr/local/bin directory. So this makes it possible to execute the command anywhere in the path, it will be still executed in relative position to the twister setup:
colibri dev build

Each twister command comes with next parts:
  1. list of arguments
  2. short description
  3. long description
  4. executable logic itself
This makes easier to define the command, but also manage a set of commands. Every module is represented as directory in the twister's root directory. Each command is located in the appropriate module directory. Built-in commands are located in the twister directory. Each module contains file _commands.py which declares what commands are exported by module.

Twister goes with list of built-in commands, that allows quickly review available modules, commands, find commands and see their documentation. Such commands are:
  • find-command - find a command in any module that matches the search criteria
  • list-commands - list all commands in all modules
  • list-modules - list all modules
  • list-aliases - list all defined aliases
Twister goes with some useful documentation in the README file.

No comments: