Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
$:.unshift("/opt/dev/vendor/deps/cli-kit/lib")
$:.unshift("/opt/dev/vendor/deps/cli-ui/lib")
require 'cli/ui'
require 'cli/kit'
CLI::UI::StdoutRouter.enable
module Stargate
extend CLI::Kit::Autocall
TOOL_NAME = 'stargate'
ROOT = File.expand_path('../..', __FILE__)
LOG_FILE = '/tmp/stargate.log'
module Commands
extend CLI::Kit::Autocall
# No point in using autoload/autocall here; it's loaded immediately by
# `register` calls.
Registry = CLI::Kit::CommandRegistry.new(
default: 'help',
contextual_resolver: nil
)
def self.register(const, cmd, path = nil, &block)
path ? autoload(const, path) : autocall(const, &block)
Registry.add(->() { const_get(const) }, cmd)
end
register(:Submit, 'submit') do
Class.new(Stargate::Command) do
def call(args, _name)
puts "submit"
end
def self.help
"Submit a stargate job.\nUsage: {{command:#{Stargate::TOOL_NAME} submit}}"
end
end
end
end
autocall(:EntryPoint) do
Module.new do
def self.call(args)
cmd, command_name, args = Stargate::Resolver.call(args)
Stargate::Executor.call(cmd, command_name, args)
end
end
end
autocall(:Config) { CLI::Kit::Config.new(tool_name: TOOL_NAME) }
autocall(:Command) { CLI::Kit::BaseCommand }
autocall(:Executor) { CLI::Kit::Executor.new(log_file: LOG_FILE) }
autocall(:Resolver) do
CLI::Kit::Resolver.new(
tool_name: TOOL_NAME,
command_registry: Stargate::Commands::Registry
)
end
autocall(:ErrorHandler) do
CLI::Kit::ErrorHandler.new(
log_file: LOG_FILE,
exception_reporter: nil
)
end
end
exit(Stargate::ErrorHandler.call do
Stargate::EntryPoint.call(ARGV.dup)
end) if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.