Skip to content

Commit

Permalink
refactor parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Adil Haritah committed Aug 4, 2015
1 parent e81838f commit bc87422
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: ruby
rvm:
- "2.0.0"
- "2.2.2"
16 changes: 2 additions & 14 deletions lib/sidekiq_client_cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'sidekiq'
require 'cli'
require_relative 'sidekiq_client_cli/version'
require_relative 'sidekiq_client_cli/parser'

class SidekiqClientCLI
COMMANDS = %w{push}
Expand All @@ -9,19 +9,7 @@ class SidekiqClientCLI
attr_accessor :settings

def parse
@settings = CLI.new do
option :config_path, :short => :c, :default => DEFAULT_CONFIG_PATH, :description => "Sidekiq client config file path"
option :queue, :short => :q, :description => "Queue to place job on"
option :retry, :short => :r, :cast => lambda { |r| SidekiqClientCLI.cast_retry_option(r) }, :description => "Retry option for job"
argument :command, :description => "'push' to push a job to the queue"
arguments :command_args, :required => false, :description => "command arguments"
end.parse! do |settings|
fail "Invalid command '#{settings.command}'. Available commands: #{COMMANDS.join(',').chomp(',')}" unless COMMANDS.include? settings.command

if settings.command == "push" && settings.command_args.empty?
fail "No Worker Classes to push"
end
end
@settings = Parser.new.parse
end

def self.cast_retry_option(retry_option)
Expand Down
21 changes: 21 additions & 0 deletions lib/sidekiq_client_cli/parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'cli'

class SidekiqClientCLI
class Parser
def parse
CLI.new do
option :config_path, :short => :c, :default => DEFAULT_CONFIG_PATH, :description => "Sidekiq client config file path"
option :queue, :short => :q, :description => "Queue to place job on"
option :retry, :short => :r, :cast => lambda { |r| SidekiqClientCLI.cast_retry_option(r) }, :description => "Retry option for job"
argument :command, :description => "'push' to push a job to the queue"
arguments :command_args, :required => false, :description => "command arguments"
end.parse! do |settings|
fail "Invalid command '#{settings.command}'. Available commands: #{COMMANDS.join(',').chomp(',')}" unless COMMANDS.include? settings.command

if settings.command == "push" && settings.command_args.empty?
fail "No Worker Classes to push"
end
end
end
end
end

0 comments on commit bc87422

Please sign in to comment.