Class: Command
- Inherits:
- 
      Object
      
        - Object
- Command
 
- Defined in:
- lib/pivotal-github/command.rb
Direct Known Subclasses
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. 
- 
  
    
      #message  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the message for the story id(s) and action (if any). 
- 
  
    
      #message_ids  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the story ids formatted for story commits. 
- #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.
| 66 67 68 69 70 71 72 73 74 75 76 | # File 'lib/pivotal-github/command.rb', line 66 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
#message ⇒ Object
Returns the message for the story id(s) and action (if any).
| 44 45 46 47 48 49 50 51 52 53 | # File 'lib/pivotal-github/command.rb', line 44 def if finish? label = "Finishes #{}" elsif deliver? label = "Delivers #{}" else label = end "[#{label}]" end | 
#message_ids ⇒ Object
Returns the story ids formatted for story commits. For single-id stories, this is just the number preceded by ‘#’, as in ‘#62831853’. For multiple-id stories, each story id is precede by ‘#’, as in ‘#62831853 #31415926’
| 59 60 61 | # File 'lib/pivotal-github/command.rb', line 59 def story_ids.map { |id| "##{id}" }.join(' ') end | 
#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 @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-62831853` gives story_id ’62831853’. New as of version 0.7, we support multiple story ids in a single branch name, so that ‘add-markdown-support-62831853-31415926` can be used to update story 62831853 and story 31415926 simultaneously.
| 34 35 36 | # File 'lib/pivotal-github/command.rb', line 34 def story_ids story_branch.scan(/[0-9]{8,}/) end |