Class: Command
- Inherits:
-
Object
- Object
- Command
- Defined in:
- lib/pivotal-github/command.rb
Direct Known Subclasses
FinishedCommand, StoryCommit, StoryOpen, StoryPull, StoryPush
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#known_options ⇒ Object
Returns the value of attribute known_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#unknown_options ⇒ Object
Returns the value of attribute unknown_options.
Class Method Summary collapse
-
.run!(command_class, args) ⇒ Object
Runs a command.
Instance Method Summary collapse
-
#initialize(args = []) ⇒ Command
constructor
A new instance of Command.
- #parse ⇒ Object
- #parser ⇒ Object
- #story_branch ⇒ Object
-
#story_id ⇒ Object
Returns the single story id for the common case of one id.
-
#story_ids ⇒ Object
Returns the story id (or ids).
Constructor Details
#initialize(args = []) ⇒ Command
Returns a new instance of Command.
8 9 10 11 12 |
# File 'lib/pivotal-github/command.rb', line 8 def initialize(args = []) self.args = args self. = OpenStruct.new parse end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/pivotal-github/command.rb', line 6 def args @args end |
#cmd ⇒ Object
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/pivotal-github/command.rb', line 6 def cmd @cmd end |
#known_options ⇒ Object
Returns the value of attribute known_options.
6 7 8 |
# File 'lib/pivotal-github/command.rb', line 6 def @known_options end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/pivotal-github/command.rb', line 6 def @options end |
#unknown_options ⇒ Object
Returns the value of attribute unknown_options.
6 7 8 |
# File 'lib/pivotal-github/command.rb', line 6 def @unknown_options end |
Class Method Details
.run!(command_class, args) ⇒ Object
Runs a command. If the argument array contains ‘–debug’, returns the command that would have been run.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pivotal-github/command.rb', line 46 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 |
Instance Method Details
#parse ⇒ Object
14 15 16 17 18 |
# File 'lib/pivotal-github/command.rb', line 14 def parse self. = Options::(parser, args) self. = Options::(parser, args) parser.parse() end |
#parser ⇒ Object
20 21 22 |
# File 'lib/pivotal-github/command.rb', line 20 def parser OptionParser.new end |
#story_branch ⇒ Object
24 25 26 |
# File 'lib/pivotal-github/command.rb', line 24 def story_branch `git rev-parse --abbrev-ref HEAD`.strip end |
#story_id ⇒ Object
Returns the single story id for the common case of one id.
39 40 41 |
# File 'lib/pivotal-github/command.rb', line 39 def story_id story_ids.first end |
#story_ids ⇒ Object
Returns the story id (or ids). We extract the story id(s) from the branch name, so that, e.g., the branch ‘add-markdown-support-6283185` gives story_id ’6283185’. New as of version 0.7, we support multiple story ids in a single branch name, so that ‘add-markdown-support-6283185-3141592` can be used to update story 6283185 and story 3141592 simultaneously.
34 35 36 |
# File 'lib/pivotal-github/command.rb', line 34 def story_ids story_branch.scan(/\d+/) end |