Class: PTTool::Application
- Inherits:
-
Object
- Object
- PTTool::Application
- Defined in:
- lib/pttool/application.rb
Overview
The command line interface to PTTool
Constant Summary collapse
- DOC =
"pttool: A tool that interfaces with pivotal tracker.\n\nUsage:\n pttool projects [--sort=<key>] [--num_members]\n pttool sync PROJECT... [--force] [--dryrun]\n pttool -h | --help\n pttool --version\n\nOptions:\n --dryrun Do a dry run of the sync, printing out end result\n [default: false].\n --force Do not prompt for confirmation [default: false].\n --num_members Output the number of members for each project\n [default: false].\n --sort=<key> Sort output by name or id [default: name].\n -h --help Show this information.\n --version Show the pttool version (\#{VERSION}).\n"
Instance Method Summary collapse
- #cmd_projects(num_members, sort) ⇒ Object
- #cmd_sync(projects, dryrun, force) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Application
29 30 31 |
# File 'lib/pttool/application.rb', line 29 def initialize @exit_status = 0 end |
Instance Method Details
#cmd_projects(num_members, sort) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/pttool/application.rb', line 33 def cmd_projects(num_members, sort) valid = %w(name id) raise Docopt::Exit, 'invalid sort option' unless valid.include?(sort) PTTool.client.projects.sort_by { |k| k.send(sort) }.each do |project| member_extra = " (#{project.memberships.size} members)" if num_members puts format("%8s: #{project.name}#{member_extra}", project.id) end end |
#cmd_sync(projects, dryrun, force) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pttool/application.rb', line 42 def cmd_sync(projects, dryrun, force) if projects.size < 2 raise Docopt::Exit, 'must list at least two projects' end require 'set' all_people = Set.new by_project = {} PTTool.client.projects.each do |project| next unless projects.include?(project.name) projects.delete(project.name) all_people.merge( by_project[project] = project.memberships.map(&:person)) end puts "Could not match: #{projects.join(', ')}" unless projects.empty? raise Error, 'too few matching projects' if by_project.size < 2 if dryrun puts "\nThe following would become members on all projects:" all_people.sort_by(&:name).each { |person| display_person(person) } by_project.each do |project, people| next unless new = all_people - people puts "\nNew members for #{project.name}:" new.sort_by(&:name).each { |person| display_person(person) } end return end by_project.each do |project, people| to_add = all_people - people next if to_add.empty? || (!force && !Helper.prompt( "Do you want to add #{to_add.size} people to #{project.name}?")) to_add.each { |person_id| Helper.add_membership(project, person_id) } end end |
#run ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/pttool/application.rb', line 81 def run handle_args(Docopt.docopt(DOC, version: VERSION)) rescue Docopt::Exit => exc exit_with_status(exc., exc.class.usage != '') rescue Error => exc exit_with_status(exc.) end |