• Stars
    star
    218
  • Rank 181,805 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command/task framework similar to rake and thor built with extendability in mind.

Description

Boson is a modular command/task framework. Thanks to its rich set of plugins, it differentiates itself from rake and thor by being usable from irb and the commandline, having automated views generated by hirb and allowing libraries to be written as plain ruby. Works with on all major rubies for ruby >= 1.9.2

New Boson

Starting with 1.0, boson has changed significantly. Please read the upgrading doc if you have an older version or if your reading about boson predates 2012.

Boson has been rewritten to have a smaller core (no dependencies) with optional plugins to hook into its various features. The major focus of 1.0 has been to provide an easy way for third-party gems to create their executable and define subcommands with options.

Docs

Nicely formatted docs are available here.

Example Executable

For a gem with an executable, bin/cow:

#!/usr/bin/env ruby
require 'boson/runner'

class CowRunner < Boson::Runner
  option :urgent, type: :boolean
  def say(text, options={})
    text.capitalize! if options[:urgent]
    puts text
  end

  def moo
    puts "MOOOO"
  end
end

CowRunner.start

You can now execute cow with say and moo subcommands:

$ cow say hungry
hungry
$ cow moo
MOOOO
# use say's urgent option
$ cow say hungry -urgent
HUNGRY

You'll notice that this syntax is powerful and concise and is very similar to thor's API. Subcommands map to ruby methods and the class represents the executable.

For some examples of executables see vimdb or tag.

Comparison to Thor

Since boson and it's rewrite are both heavily inspired by thor, it makes sense to compare them.

First, what I consider pros boson has over thor. Boson

  • is designed to handle plugins. This means it core parts are extendable by modules and core components like commands can have arbitrary metadata associated with them.
  • has a rich set of plugins. See boson-more.
  • has commands that are easily testable. Whereas thor has options that automagically appear in command methods, boson explicitly passes options to its command method as a hash i.e. MyRunner.new.subcommand(arg, verbose: true). This also allows commands to just be called as ruby, with no magic to consider.
  • supports custom-user option types i.e. creating a Date option type. See Boson::Options.
  • supports custom method decorators i.e. methods like desc that add functionality to a command. While boson supports option, options, desc and config out of the box, users can create their own.
  • automatically creates usage for your subcommand. With thor you need to manually define your usage with desc: desc "SOME USAGE", "SOME DESCRIPTION"
  • is lenient about descriptions. Describe commands at your leisure. With thor you must define a desc.
  • has no blacklist for command names while thor has a blacklist due to its design. With boson you can even name commands after Kernel method names but tread with caution in your own Runner class.
  • allows for user-defined default global options (i.e. --help) and commands (i.e. help). This means that with a plugin you could have your own additional default options and commands shared across executables. See the extending section below.
  • allows default help and command help to be overridden/extended by subclassing Runner.display_help and Runner.display_command_help respectively.
  • provides an optional custom rc file for your executable. Simply set ENV['BOSONRC'] to a path i.e. ~/.myprogramrc. This rc file loads before any command processing is done, allowing for users to extend your executable easily i.e. to add more subcommands. For an example, see vimdb.

Now for pros thor has over boson. Thor

  • is widely used and thus has been community QAed thoroughly.
  • supports generators as a major feature.
  • is more stable as its feature set is mostly frozen.
  • is used by rails and thus is guaranteed support for some time.
  • supports ruby 1.8.7.
  • can conveniently define an option across commands using class_option. boson may add this later.
  • TODO: I'm sure there's more

Converting From Thor

  • Change your requires and subclass from Boson::Runner instead of Thor.
  • Delete the first argument from desc. Usage is automatically created in boson.
  • Rename method_option to option
  • For options with a type option, make sure it maps to a symbol i.e. :array or :boolean. If left a string, the option will be interpreted to be a string option with that string as a default.
  • class_option doesn't exist yet but you can emulate it for now by defining your class option in a class method and then calling your class method before every command. See vimdb for an example.

Writing Plugins

A Boson plugin is a third-party library that extends Boson through its extension API. Any Boson class/module that includes or extends a module named API or APIClassMethods provides an extension API. Examples of such classes are Boson::BareRunner, Boson::Command, Boson::Inspector and Boson::Library. As an example, let us extend what any boson-based executable does first, extend Boson::BareRunner.start:

module Boson
  module CustomStartUp
    def start(*)
      super
      # additional startup
    end
  end
end

Boson::BareRunner.extend Boson::CustomStartUp

Notice that extend was used to extend a class method. To extend an instance method you would use include. Also notice that you use super in an overridden method to call original functionality. If you don't, you're possibly overridden existing functionality, which is fine as long as you know what you are overriding.

If you want to gemify your plugin, name it boson-plugin_name and put it under lib/boson/plugin_name. The previous example would go in lib/boson/custom_startup.rb. To use your plugin, a user can simply require your plugin in their executable.

For many plugin examples, see boson-more.

Using a Plugin

To use a plugin, just require it. For an executable:

require 'boson/runner'
require 'boson/my_plugin'

MyRunner.start

For the boson executable, just require the plugins in ~/.bosonrc.

Extending Your Executables

Boson allows for custom default options and commands. This means you can add your own defaults in a plugin and use them across your executables.

To add a custom default command, simply reopen Boson::DefaultCommandsRunner:

class Boson::DefaultCommandsRunner
  desc "whoomp"
  def whoomp
    puts "WHOOMP there it is!"
  end
end

To add a custom global option, add to Boson::Runner::GLOBAL_OPTIONS:

Boson::Runner::GLOBAL_OPTIONS.update(
  verbose: {type: :boolean, desc: "Verbose description of loading libraries"}
)

Custom global options are defined in the same format as options for a command.

Bugs/Issues

Please report them on github. If the issue is about upgrading from old boson, please file it in boson-more.

Contributing

See here

Motiviation

Motivation for the new boson is all the damn executables I'm making.

Credits

Boson stands on the shoulders of these people and their ideas:

  • Contributors: @mirell, @martinos, @celldee, @zhando
  • Yehuda Katz for Thor and its awesome option parser (Boson::OptionParser).
  • Daniel Berger for his original work on thor's option parser.
  • Chris Wanstrath for inspiring Boson's libraries with Rip's packages.

More Repositories

1

hirb

A mini view framework for console/irb that's easy to use, even while under its influence. Console goodies include a no-wrap table, auto-pager, tree and menu.
Ruby
1,637
star
2

ripl

ruby interactive print loop - A light, modular alternative to irb
Ruby
395
star
3

tux

Sinatra dressed for interactive ruby - a sinatra shell
Ruby
301
star
4

bond

Mission: Easy custom autocompletion for arguments, methods and beyond. Accomplished for irb and any other readline-like console environments.
Ruby
233
star
5

one9

commandline tool to convert 1.8 code to ruby 1.9.2. So what's your excuse for not upgrading to 1.9.2? ;)
Ruby
171
star
6

logseq-query

Clojure
159
star
7

vimdb

vim knowledge tabularized - search vim keys, options and more with great precision.
Ruby
157
star
8

table

Display ascii tables for almost any data structure with ease.
Clojure
107
star
9

lightning

Speed for your shell and the commandline
Ruby
74
star
10

bahia

commandline acceptance testing - aruba for non-cucumber test frameworks
Ruby
52
star
11

nirvana

A ruby web shell that is very ape and very nice
JavaScript
52
star
12

datomic-free

A wrapper around datomic-free to easily start and upgrade it
Shell
51
star
13

irbfiles

ripl/irb the way I like it (enhanced with boson)
Ruby
50
star
14

datomico

Use datomic with intention revealing names. Ease of use and sticking to datomic's principles are encouraged.
Clojure
49
star
15

bb-clis

Babashka CLIs
Clojure
48
star
16

has_machine_tags

A rails tagging gem implementing flickr's machine tags + maybe more (semantic tags)
Ruby
44
star
17

debugger-completion

Mission: auto-complete debugger
Ruby
43
star
18

datomic-client

ruby client for datomic's http api
Ruby
41
star
19

tag-tree

Explores the wicked combo of machine tag queries + their results as trees.
Ruby
28
star
20

alias

Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more.
Ruby
25
star
21

console_update

A gem to edit your database records via the console and your favorite editor.
Ruby
21
star
22

ltfiles

my light table dotfiles
JavaScript
20
star
23

gem_grep

*Not being maintained. Any takers?* A gem command plugin which enhances the search command by providing extra search options and displaying results as a table.
Ruby
17
star
24

machinetag.js

jQuery plugins to search/parse machine tags and display machine tag trees.
JavaScript
16
star
25

dotfiles

config files for my most used apps
Shell
15
star
26

rubydoc

A repl tool to help rubyists find clojure equivalents
Clojure
15
star
27

wolf

Devour computational knowledge on the commandline with wolframalpha
Ruby
14
star
28

ripl-play

A ripl plugin to playback and record inputs in ripl
Ruby
14
star
29

logseq-config

13
star
30

ripl-rails

alternative to script/console using ripl
Ruby
11
star
31

dlint

Lint datomic-style datalog queries and rules. For clojure and clojurescript
Clojure
11
star
32

osx-setup

Set up my osx environment with a one-liner
Ruby
11
star
33

Mermaid

Light Table plugin that generates diagrams and flowcharts from text using mermaid
JavaScript
11
star
34

datomic-box

[wip] Spin up a running Datomic Free box from the commandline. Done.
Clojure
10
star
35

rbenv-travis

Run travis tests locally using rbenv rubies
Ruby
10
star
36

local_gem

Load/require any gem/library simply given its path. Great for nascent gems or for trying the latest code on a gem.
Ruby
10
star
37

lein-spell

Catch spelling mistakes in programming documents and clojure docstrings.
Clojure
9
star
38

gitbeam

Light Table plugin for seamless github interaction
JavaScript
9
star
39

sacha

An outliner for Light Table
JavaScript
9
star
40

photon

Light Table plugin to quickly open your most active projects
Clojure
9
star
41

gh-active-issues

A pedestal service that helps github maintainers grapple with their issues and helps users understand what's before their issue
Clojure
8
star
42

Sancho

Your trusty Clojure(Script) sidekick for LightTable. Includes grimoire and crossclj integration
JavaScript
8
star
43

Share

Collaborative editing for Light Table
JavaScript
7
star
44

nbb-clis

Nbb CLIs
Clojure
7
star
45

leinfiles

Handy functions for a clojure repl - most likely lein repl
Clojure
7
star
46

boson-more

Home for boson2 plugins
Ruby
7
star
47

queriac

Picking up where Yubnub left off..
Ruby
6
star
48

ripl-rack

script/console for rack using ripl
Ruby
6
star
49

ripl-em

interact with eventmachine code - asynchronously of course
Ruby
6
star
50

ripl-irb

A ripl plugin to smooth the transition from irb
Ruby
6
star
51

rbenv-plugin

Manage rbenv plugins
Ruby
6
star
52

tag

tag anything from the commandline
Ruby
6
star
53

ripl-commands

This ripl plugin adds commands to ripl that are similar to irb's
Ruby
6
star
54

ripl-hijack

hijack a ruby process a la ripl
Ruby
5
star
55

ripl-johnson

A full-featured javascript shell using johnson (mozilla's tracemonkey)
Ruby
5
star
56

ripl-i18n

A ripl plugin that let's ripl speak your language
Ruby
4
star
57

repl.js

jquery plugin to replify an html element
JavaScript
4
star
58

previewradio-pedestal

a sinatra to pedestal-service comparison
Clojure
4
star
59

sinatra-bootstrap

sinatra app bootstrapped by bootstrap and some
JavaScript
4
star
60

ripl-misc

some misc ripl plugin ideas
Ruby
4
star
61

ripl-color_error

ripl plugin to colorize errors
Ruby
4
star
62

lein-grep

A Leiningen plugin that renders meaningful search results.
Clojure
4
star
63

urls

easy bookmarking for the commandline and beyond
Ruby
4
star
64

bond-yard

bond plugin to generate completions for yard-documented methods
Ruby
3
star
65

fda-events

Exploratory app for FDA's drug adverse event API
Clojure
3
star
66

core

*Unfinished* Easily use and share your ruby extensions and other extension libraries ie ActiveSupport, facets
Ruby
3
star
67

lein-open

Open a jar in an editor easily
Clojure
3
star
68

emoji

middleware/interceptorware to add bundled emoji images
Clojure
3
star
69

github-contributions

App to show a github user's forks and contributions to each one. Using pedestal and SSE
Clojure
3
star
70

jrepl

*Work in progress* javascript shell with readline and autocompletion
JavaScript
3
star
71

bacon-bits

Making bacon a little tastier
Ruby
3
star
72

smart-ignore

LT plugin that auto-updates ignore-pattern based on current directories in a workspace
JavaScript
3
star
73

github_user_page.js

*broken with new layout* jquery plugin/ github bookmarklet to enhance github's user pages
JavaScript
3
star
74

emojinator

a silly app that slurps a url and emojinates any word that matches an emoji name
Clojure
2
star
75

sse-chat

simple sse chat example for pedestal, ported from sinatra
Clojure
2
star
76

ripl-debug

A ripl plugin that automatically passes a failed eval to ruby-debug
Ruby
2
star
77

bolt

[work in progress] - web commands a la queriac, done all clientside with rum/reactjs
Clojure
2
star
78

menu

More choices with less typing
Ruby
2
star
79

ripl-after_rc

A ripl plugin that defines blocks to run after ~/.irbrc
Ruby
2
star
80

logseq-clis

CLIs for logseq using nbb-logseq
Clojure
2
star
81

bacon-rr

rr adapter for bacon
Ruby
2
star
82

om-components

A collection of reusable om components [WIP]
Clojure
2
star
83

bender

smack-talking hubot
CoffeeScript
2
star
84

vimfiles

no horses were harmed while horsing around with this vim setup
Vim Script
2
star
85

websh

A sinatra web shell using ripl that deploys on Heroku.
JavaScript
2
star
86

robolot

your faithful async knight
Ruby
1
star
87

emacs.d

An emacs config based on emacs-starter-kit - optimized for ruby and clojure.
Emacs Lisp
1
star
88

ripl-ripper

ripl plugin for a multi-line ripl using ripper
Ruby
1
star
89

pedestal-dataflow-logger

An experiment in logging pedestal-app dataflow internals
Clojure
1
star
90

urls-web

web interface to urls
JavaScript
1
star
91

atomfiles

JavaScript
1
star
92

semtag.me

pedestal app that communicates via clojure data using CORS requests
Clojure
1
star
93

rip-licious

A tasty collection of rip plugins
Ruby
1
star
94

rip-ext

Rip plugin to easily synchronize gem environments across ruby versions
Ruby
1
star
95

psycho

Going psycho with syck to psych conversions? Let psycho handle this syck-psych-o-ness!
Ruby
1
star
96

is_it_ec2

is it ec2?
JavaScript
1
star
97

readline.js

jquery plugin to bring readline to the hoi polloi
JavaScript
1
star
98

migration_sql

Generate migration sql for Rails apps and Sequel
Ruby
1
star
99

link-checker

A multi-threaded link-checker powered by pedestal and SSE
Clojure
1
star
100

git-puns

Atom package to git some git laughs
Clojure
1
star