Skip to content

Commit

Permalink
Add support for CLI and options, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Nov 28, 2023
1 parent 267b2b5 commit 59477ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
6 changes: 4 additions & 2 deletions bin/kuiq
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

$LOAD_PATH.unshift File.expand_path(File.join(__dir__, '..', 'lib'))

require "kuiq/sidekiq_ui"
require "kuiq/cli"

Kuiq::SidekiqUI.launch
cli = Kuiq::CLI.instance
cli.parse
cli.run
47 changes: 47 additions & 0 deletions lib/kuiq/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "singleton"
require "optparse"
require "sidekiq"
require "sidekiq/api"
require "kuiq/version"
require "kuiq/i18n"

module Kuiq
class CLI
include Singleton

DEFAULTS = {
verbose: false,
action: :gui
}

def parse
@options = DEFAULTS.dup
OptionParser.new do |opts|
opts.banner = "Usage: #{opts.program_name} [options]"
opts.on("-v", "Use verbose logging") do |v|
@options[:verbose] = v
end
end.parse!

logger.level = (@options[:verbose] ? :info : :warn)
@options
end

def gui
require "kuiq/gui"
Kuiq::GUI.launch
end

def run
logger.info { "Kuiq #{Kuiq::VERSION}, using the #{I18n.current_locale.upcase} locale" }
logger.info { RUBY_DESCRIPTION }
logger.info { "Redis client #{RedisClient::VERSION}, server #{Sidekiq.default_configuration.redis_info["redis_version"]}" }

send(@options[:action])
end

def logger
Sidekiq.logger
end
end
end
8 changes: 1 addition & 7 deletions lib/kuiq/sidekiq_ui.rb → lib/kuiq/gui.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "sidekiq"
require "sidekiq/api"
require "glimmer-dsl-libui"

require "kuiq"
Expand All @@ -12,15 +10,11 @@
require "kuiq/view/morgue"

module Kuiq
class SidekiqUI
class GUI
include Glimmer::LibUI::Application

before_body do
logger.info { "Welcome to Kuiq #{Kuiq::VERSION}, using the #{I18n.current_locale.upcase} locale" }
logger.info { RUBY_DESCRIPTION }

@job_manager = Model::JobManager.new
logger.info { "Redis client #{RedisClient::VERSION}, server #{@job_manager.redis_info["redis_version"]}" }
end

after_body do
Expand Down

0 comments on commit 59477ee

Please sign in to comment.