Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: martinciu/issues
base: 3011ef0289
...
head fork: martinciu/issues
compare: 51923c6e2f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
6 lib/issues/command.rb
@@ -7,10 +7,10 @@
require 'issues/command/base'
require 'issues/command/authenticated'
require 'issues/command/with_repo'
-
require 'issues/command/main'
-require 'issues/command/help'
-require 'issues/command/milestones'
+
+require 'issues/commands/help'
+require 'issues/commands/milestones'
module Issues
module Command
View
19 lib/issues/command/config.rb
@@ -0,0 +1,19 @@
+module Issues
+ module Command
+ module Config
+
+ def self.included(base)
+ base.extend ClassMethods
+ base.send(:include, Hooks)
+ base.send(:alias_method, :initialize_without_config, :initialize)
+ base.send(:alias_method, :initialize, :initialize_with_config)
+ base.after_initialize :parse_config
+ end
+
+ private
+
+ end
+ end
+end
+
+
View
22 lib/issues/command/options/config_parser.rb
@@ -0,0 +1,22 @@
+module Issues
+ module Command
+ module Options
+
+ class ConfigParser
+ def initialize(options, path)
+ self.options, self.path = options, path
+ end
+
+ def parse
+ options
+ end
+
+ private
+ attr_accessor :options, :path
+ end
+
+ end
+ end
+end
+
+
View
13 lib/issues/command/options/group.rb
@@ -4,8 +4,17 @@ module Options
class Group
extend Forwardable
+ include Enumerable
def_delegators :options, :each, :find, :<<
+ def merge(other)
+ other.each do |option|
+ options << option unless include?(option)
+ end
+
+ self
+ end
+
def initialize(options = [])
options ||= []
options.each do |option|
@@ -17,6 +26,10 @@ def fetch(name)
find { |option| option.name == name.to_s }
end
+ def <=>(ohter)
+ name == other.name.to_s
+ end
+
private
def options
@options ||= []
View
34 lib/issues/command/options/options_parser.rb
@@ -0,0 +1,34 @@
+module Issues
+ module Command
+ module Options
+
+ class OptionsParser
+ def initialize(options, args)
+ self.options, self.args = options, args
+ end
+
+ def parse
+ parser.parse!
+
+ options
+ end
+
+ private
+ attr_accessor :options, :args
+
+ def parser
+ OptionParser.new do |parser|
+ options.each do |option|
+ parser.on(*option.args) do |value|
+ option.value = value
+ end
+ end
+ end
+ end
+ end
+
+ end
+ end
+end
+
+
View
26 lib/issues/command/options/parser.rb
@@ -1,3 +1,6 @@
+require 'issues/command/options/options_parser'
+require 'issues/command/options/config_parser'
+
module Issues
module Command
module Options
@@ -8,25 +11,26 @@ def initialize(klass, args)
end
def parse
- parser.parse!(args)
-
- options
+ parsers.inject(Group.new) { |group, parser| group.merge(parser.parse) }
end
private
attr_accessor :klass, :args
+
def options
klass.options
end
- def parser
- OptionParser.new do |parser|
- options.each do |option|
- parser.on(*option.args) do |value|
- option.value = value
- end
- end
- end
+ def options_parser
+ OptionsParser.new(options, args)
+ end
+
+ def config_parser(path)
+ ConfigParser.new(options, path)
+ end
+
+ def parsers
+ [config_parser("~/.issues"), config_parser(".issues"), options_parser]
end
end
View
2  lib/issues/command/resolver.rb
@@ -47,7 +47,7 @@ def classify(string)
end
def namespaced(class_name)
- "Issues::Command::#{class_name}"
+ "Issues::Commands::#{class_name}"
end
end
View
2  lib/issues/command/help.rb → lib/issues/commands/help.rb
@@ -1,5 +1,5 @@
module Issues
- module Command
+ module Commands
class Help
include Issues::Command::Base
View
2  lib/issues/command/milestones.rb → lib/issues/commands/milestones.rb
@@ -1,5 +1,5 @@
module Issues
- module Command
+ module Commands
class Milestones
include Issues::Command::Base

No commit comments for this range

Something went wrong with that request. Please try again.