Sha256: d89e00d6facbe4846b3f7bb16bfe7426672d9e74df3edb2e1fe5a45d50397013
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
class Command attr_accessor :args, :cmd, :options, :known_options, :unknown_options def initialize(args = []) self.args = args parse end def parse raise "Define in derived class" end def current_branch `git rev-parse --abbrev-ref HEAD`.strip end def story_id current_branch.scan(/\d+/).first end def options @options ||= parse end # Runs a command # If the argument array contains '--debug', returns the command that would # have been run def self.run!(command_class, args) debug = args.delete('--debug') command = command_class.new(args) if debug puts command.cmd return 1 else command.run! return 0 end end private # Returns an argument string based on given arguments # The main trick is to add in quotes for option # arguments when necessary. # For example, ['-a', '-m', 'foo bar'] becomes # '-a -m "foo bar"' def argument_string(args) args.inject([]) do |opts, opt| opts << (opt =~ /^-/ ? opt : opt.inspect) end.join(' ') end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pivotal-github-0.5.1 | lib/pivotal-github/command.rb |
pivotal-github-0.5.0 | lib/pivotal-github/command.rb |