Class: PivotalShell::Commands::Stories
- Inherits:
-
PivotalShell::Command
- Object
- PivotalShell::Command
- PivotalShell::Commands::Stories
- Defined in:
- lib/pivotal_shell/commands/stories.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ Stories
constructor
A new instance of Stories.
Constructor Details
#initialize(options) ⇒ Stories
Returns a new instance of Stories.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pivotal_shell/commands/stories.rb', line 5 def initialize() @options = {:params => {}} opts = OptionParser.new do |opts| opts. = "List Pivotal stories\nUsage: pivotal stories [options]\n\nThe default is to show all unfinished stories assigned to yourself\n\nDisplay format:\n [id]\n type: Feature/Bug/Chore\n estimate: * (irrelevant)/0/1/2/3\n state: . (unscheduled)/Unstarted/Started/Finished/Delivered/Accepted/Rejected\n title\n\nOptions:" opts.on('--all', 'Show all tasks (reset default filter on state and owner)') do @options[:all] = true end PivotalShell::Cache::Story::STATUSES.each do |status| opts.on("--#{status}", "Show #{status} stories") do @options[:params][:state] ||= [] @options[:params][:state] << status end end PivotalShell::Cache::Story::TYPES.each do |type| opts.on("--#{type}s", "Show #{type}") do @options[:params][:type] ||= [] @options[:params][:type] << type end end opts.on('--for [USER]', 'Show tasks assigned to USER; accepts comma-separated list') do |user| @options[:params][:owner] = user end opts.on('--unowned', 'Show tasks not assigned to anyone') do @options[:params][:unowned] = true end opts.on('--anyone', 'Show tasks assigned to anyone') do @options[:anyone] = true end opts.on('--mine', 'Show your tasks') do @options[:params][:owner] = PivotalShell::Configuration.me end opts.on_tail('--help', 'Show this help') do puts opts exit end end opts.parse! @options[:params][:owner] ||= PivotalShell::Configuration.me unless @options[:unowned] || @options[:anyone] || @options[:all] @options[:params][:state] ||= %w(unestimated unstarted started) unless @options[:all] end |
Instance Method Details
#execute ⇒ Object
58 59 60 61 62 |
# File 'lib/pivotal_shell/commands/stories.rb', line 58 def execute stories = PivotalShell::Cache::Story.all(@options[:params]) puts stories.empty? ? 'No stories!' : stories.map{|s| "#{("[#{s.id}]").rjust 12} #{PivotalShell::Configuration.icon(s.story_type, s.current_state, s.estimate)} #{s.name.strip}"}.join("\n") end |