Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion bin/codeunion
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,53 @@ bin_file = Pathname.new(__FILE__).realpath
$LOAD_PATH.unshift File.expand_path("../../lib", bin_file)

# Add our gem-specific "libexec" directory to the PATH
ENV["PATH"] += ":" + File.expand_path("../../libexec", bin_file)
subcmd_dir = File.expand_path("../../libexec", bin_file)
ENV["PATH"] += ":" + subcmd_dir

# Find all available subcommands
subcmd_prefix = "codeunion-"
subcmd_files = Pathname.glob(File.join(subcmd_dir, subcmd_prefix + "*"))

SUBCOMMANDS = subcmd_files.map do |path|
path.basename.to_s[/#{subcmd_prefix}(.+)/, 1]
end

require "codeunion/command/main"
require "optparse"

description = <<HELP
The CodeUnion command-line tool is meant to be used in conjunction with CodeUnion's curriculum.

Think of it as your "learning sherpa."
HELP

parser = OptionParser.new do |opts|
opts.instance_exec do
self.banner = "Usage: codeunion <command>"

separator ""
separator description

separator ""
separator "Commands:"
separator SUBCOMMANDS.map { |subcmd| summary_indent + subcmd }

separator ""
separator "Options:"

on_tail("-h", "--help", "Print this help message") do
puts self
exit
end
end
end

parser.order!

if ARGV.empty?
puts parser
exit
end

options = {
:command_name => ARGV.first,
Expand Down