Sha256: ef3ffc247e5587addee304ae55e389d34800ac4f722aa29df6b1bbf946555548

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 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

unless $LOAD_PATH.resolve_feature_path("discorb/exe/#{command}.rb")
  warn "Unknown subcommand: #{command}"
  abort
end
require "discorb/exe/#{command}"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
discorb-0.20.0 exe/discorb
discorb-0.19.0 exe/discorb
discorb-0.18.1 exe/discorb
discorb-0.18.0 exe/discorb