Sha256: d7d5329a5dd5f1f2c9e20a2b5bfbeaa96e57c0207f32f5184e361a43957749ad

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

#! /usr/bin/env ruby
# frozen_string_literal: true

require "optparse"

options = {
  bundler: true,
}
discorb_paths = $LOAD_PATH.filter { |path| File.directory?(path + "/discorb") }
scripts = {}
discorb_paths.each do |discorb_path|
  Dir.glob(discorb_path + "/discorb/exe/*.rb") do |exe_script|
    name = File.basename(exe_script, ".rb")
    description = File.read(exe_script).match(/# description: (.+)/)&.[](1) || "No description"
    scripts[name] = description
  end
end
max_length = scripts.keys.map(&:length).max
global = OptionParser.new do |opts|
  opts.banner = "Usage: discorb [options] [subcommand [options]]"
  opts.on("-b", "--[no-]bundler", "Whether to use bundler.") do |v|
    options[:bundler] = v
  end
  opts.separator ""
  commands = +"Subcommands:\n"
  commands << scripts.sort.map do |name, description|
    "  #{name.rjust(max_length)} - #{description}"
  end.join("\n")
  commands << "\n\nYou can run `discorb [subcommand] --help` for more information."
  opts.separator commands
end
global.order!(ARGV)

if ARGV.empty?
  puts global
  abort
end

require "bundler/setup" if options[:bundler]

command = ARGV.shift

begin
  require "discorb/exe/#{command}"
rescue LoadError
  warn "Unknown subcommand: #{command}"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discorb-0.17.1 exe/discorb
discorb-0.17.0 exe/discorb