Sha256: 52ca0970a25d4083f513760738f1ea298048f410f78703c34cec5d6b862a317e

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true
# description: Setup application commands.
require "optparse"
require "discorb/utils/colored_puts"

ARGV.delete_at 0

options = {
  guilds: nil,
  script: true,
}

opt = OptionParser.new <<~BANNER
                         This command will setup application commands.

                         Usage: discorb setup [options] [script]

                                   script                     The script to setup.
                       BANNER
opt.on("-g", "--guild ID", Array, "The guild ID to setup, use comma for setup commands in multiple guilds, or `global` for setup global commands.") { |v| options[:guilds] = v }
opt.on("-s", "--[no-]script", "Whether to run `:setup` event. This may be useful if setup script includes operation that shouldn't run twice. Default to true.") { |v| options[:script] = v }
opt.parse!(ARGV)

script = ARGV[0]
script ||= "main.rb"
ENV["DISCORB_CLI_FLAG"] = "setup"

ENV["DISCORB_SETUP_GUILDS"] = if options[:guilds] == ["global"]
  "global"
elsif options[:guilds]
  options[:guilds].join(",")
end

ENV["DISCORB_SETUP_SCRIPT"] = options[:script].to_s if options[:script]

begin
  load script
rescue LoadError
  eputs "Could not load script: \e[31m#{script}\e[m"
else
  sputs "Successfully set up commands for \e[32m#{script}\e[m."
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
discorb-0.16.0 lib/discorb/exe/setup.rb
discorb-0.15.1 lib/discorb/exe/setup.rb
discorb-0.15.0 lib/discorb/exe/setup.rb
discorb-0.14.0 lib/discorb/exe/setup.rb