Git Product home page Git Product logo

bevel's Introduction

bevel

A simple, shell script subcommand framework.

Overview

bevel takes a directory with a particular structure and maps each file in the directory tree to a subcommand.

For example, given the following directory structure...

myapp/
├── db
│   ├── cluster
│   │   ├── _driver
│   │   └── status
│   ├── create
│   ├── destroy
│   ├── _driver
│   └── migrate
└── _driver

...bevel will create a CLI app that matches the tree, e.g. commands might look something like:

$ myapp db cluster status
Cluster OK!
$ myapp
usage: myapp <subcommand> [subcommands] [options] [arguments]

Valid subcommands: db

$ myapp db
usage: myapp db [subcommands] [options] [arguments]

Valid subcommands: cluster, create, destroy, migrate

Writing a bevel App

To generate a bevel app, first plan out your command hierarchy with plain old directories and files. A directory corresponds to a command which has subcommands, and a file corresponds to a command which does not have other subcommands.

Next, each directory needs to have a special file called _driver. This script implements the execution of the parent command. Typically, this script will simply print the valid subcommands.

Lastly, you need to ensure that each of your scripts meets two criteria:

  • Scripts must be readable and executable.
  • Scripts must have a shebang line (e.g. #!/bin/bash) which indicates the runtime to use when executing the script.

The only caveat to these criteria is that you may leave driver scripts (_driver) empty. When this is done, bevel will print a default usage message which simply shows the valid subcommands for the parent command, e.g.:

$ cat /path/to/myapp/_driver
$ myapp
usage: myapp <subcommand> [arguments] [options]

Valid subcommands are: db 

Other than that, if any of these criteria are not true, bevel will simply disregard the file (i.e. won't consider it a command).

To aid in the detection of problems, bevel provides the --verify option. When run against your command hierarchy, it will let you know if there are any obvious problems. In some cases (e.g. if you have a README), "bad" results are simply false positives and can be ignored.

Wiring Up the App

Now that you have your command hierarchy set up, you'll need to write a driver. To do this, simply generate a wrapper script and call bevel with the appropriate arguments.

For example, create /usr/bin/myapp with these contents:

#!/bin/bash

bevel --bindir /path/to/myapp/ --args "$*"

(Here, /path/to/myapp/ is the directory containing the top-most _driver file in your command hierarchy.)

When a user executes this wrapper, bevel will delegate execution to the appropriate command or subcommand in the command hierarchy you established previously.

Autocompletion

bevel will automatically generate subcommand completion for you. All you need to do is edit your .bashrc or create a script in /etc/profile.d, and call bevel with the --complete option.

For example:

#!/bin/bash

COMPLETER="bevel --bindir /path/to/myapp/ --complete"

complete -C "$COMPLETER" myapp

bevel's People

Contributors

jcmcken avatar

Watchers

 avatar  avatar

bevel's Issues

Configure logging

At least implement a ''BEVEL_DEBUG" env var to enable stdout/err logging,

Allow app_name override

Currently, bevel uses the dirname of --bindir to determine the app name. Allow user to override this via a command-line option

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.