Skip to content

Instantly share code, notes, and snippets.

View Benabik's full-sized avatar

Brian Gernhardt Benabik

View GitHub Profile
@Benabik
Benabik / optparse_subcommand.rb
Last active August 27, 2023 02:36
A Ruby class for turning command line options into keyword arguments and subcommands into method calls.
# frozen_string_literal: true
require 'forwardable'
require 'ostruct'
require 'optparse'
# This class extends OptionParser to handle git style subcommands. Users of
# this class create a OptionParser::Subcommand object, set up the options using
# OptionParser methods, and then pass a class to OptionParser::Subcommand#run.
# Command line options before the first argument are passed as keyword