Sha256: 8acf2b3b53670af2a6c136d3a14464cb19d4c3d81ba645e3c852fc751908dde9
Contents?: true
Size: 1.42 KB
Versions: 9
Compression:
Stored size: 1.42 KB
Contents
# description: Run a client. require "optparse" require "json" require "discorb/utils/colored_puts" ARGV.delete_at 0 # @!visibility private LOG_LEVELS = %w[none debug info warn error fatal] opt = OptionParser.new <<~BANNER This command will run a client. Usage: discorb run [options] [script] script The script to run. Defaults to 'main.rb'. BANNER options = { deamon: false, log_level: nil, log_file: nil, log_color: nil, setup: nil, } opt.on("-d", "--deamon", "Run as a daemon.") { |v| options[:daemon] = v } opt.on("-l", "--log-level LEVEL", "Log level.") do |v| unless LOG_LEVELS.include? v.downcase eputs "Invalid log level: \e[31m#{v}\e[91m" eputs "Valid log levels: \e[31m#{LOG_LEVELS.join("\e[91m, \e[31m")}\e[91m" exit 1 end options[:log_level] = v.downcase end opt.on("-f", "--log-file FILE", "File to write log to.") { |v| options[:log_file] = v } opt.on("-c", "--[no-]log-color", "Whether to colorize log output.") { |v| options[:log_color] = v } opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v } opt.parse!(ARGV) script = ARGV[0] script ||= "main.rb" ENV["DISCORB_CLI_FLAG"] = "run" ENV["DISCORB_CLI_OPTIONS"] = JSON.generate(options) begin load script rescue LoadError eputs "Could not load script: \e[31m#{script}\e[91m" end
Version data entries
9 entries across 9 versions & 1 rubygems