Commit 09dee240 authored by Jyrki's avatar Jyrki 🐾

Move Commands to UseCase::CliCommands

parent d76afe94
require "./commands/start_bot"
require "logger"
require "./use_case/cli_commands/start_bot"
class Application
COMMANDS = {
"start" => Commands::StartBot
"start" => UseCase::CliCommands::StartBot
}
def self.run(argv)
......
require "colorize"
require "../errors"
module Commands
abstract class Base
def self.call(argv)
new(argv).call
rescue e : Errors::Base
STDERR.print "#{e.human_name}: ".colorize(:light_red)
STDERR.puts e.message
exit 2
end
def self.description
""
end
def initialize(@argv : Array(String))
end
abstract def call
end
end
require "./base"
require "../bot"
require "../errors"
module Commands
class StartBot < Base
def self.description
"Starts the telegram bot."
end
def call
check_sanity!
Bot.new.start
end
private def check_sanity!
unless ENV.has_key?("TELEGRAM_API_TOKEN")
raise Errors::ConfigurationError.new("TELEGRAM_API_TOKEN is not set")
end
end
end
end
require "colorize"
require "../base"
require "../../errors"
module UseCase
module CliCommands
abstract class Base < UseCase::Base
def self.call(argv)
super
rescue e : Errors::Base
STDERR.print "#{e.human_name}: ".colorize(:light_red)
STDERR.puts e.message
exit 2
end
def self.description
""
end
end
end
end
require "./base"
require "../../bot"
require "../../errors"
module UseCase
module CliCommands
class StartBot < CliCommands::Base
def self.description
"Starts the telegram bot."
end
def call(_argv)
check_sanity!
Bot.new.start
end
private def check_sanity!
unless ENV.has_key?("TELEGRAM_API_TOKEN")
raise Errors::ConfigurationError.new("TELEGRAM_API_TOKEN is not set")
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment