#!/usr/bin/env ruby require 'gli' require 'pgit' include GLI::App program_desc 'Optimize your Pivotal Tracker and Git workflow' version Pgit::VERSION subcommand_option_handling :normal arguments :strict desc "Color output" default_value :true switch :color desc "Print backtrace if there is an exception" switch :trace # desc 'Path to the config file' # default_value "#{ENV['HOME']}/.pgit.rc.yml" # arg_name '/path/to/.pivotal.yml' # flag [:c,:config] # desc 'Bypasses the app asking for confirmation' # switch [:force] # desc 'PivotalTracker API Token' # arg_name 'secr3tT0ken123' # flag [:'api-token'] desc "Work with projects" command :proj do |p| p.desc "add a project" p.command :add do |a| a.desc "the id associated to the Pivotal Tracker project" a.arg_name '12030405' a.flag :d, :id a.desc "the filepath that is going to be associated to the Pivotal Tracker and Git project" a.arg_name '"/some/file/path"' a.default_value Dir.pwd a.flag :p, :path a.desc "your Pivotal Tracker API token" a.arg_name "token" a.flag :t, :api_token a.action do |global_options,options,args| app = PGit::Project::Application.new(global_options, options, args) add = PGit::Project::Add.new(app) add.execute! end end p.desc "remove a project" p.command :rm do |a| a.desc "the path whose pgit project will be removed" a.arg_name '"/some/file/path"' a.default_value Dir.pwd a.flag :p, :path a.action do |global_options,options,args| app = PGit::Project::Application.new(global_options, options, args) rm = PGit::Project::Remove.new(app) rm.execute! end end end desc "Work with custom commands defined in the current project" command :cmd do |c| c.desc "show the custom command(s)" c.arg_name 'command_name' c.command :show do |s| s.action do |global_options,options,args| app = PGit::Command::Application.new(global_options, options, args) show = PGit::Command::Show.new(app) show.execute! end end c.desc "run a command" c.arg_name 'command_name' c.command :run do |r| r.action do |global_options,options,args| app = PGit::Command::Application.new(global_options, options, args) run = PGit::Command::Run.new(app) run.execute! end end c.desc "add a command" c.command :add do |a| accept(Array) do |value| value.split(',').map {|item| item.strip } end a.desc "name of the command" a.arg_name "new_command_name" a.flag :n, :name, required: true a.desc "steps of the command, delimited by commas" a.arg_name "steps" a.flag :s, :steps, required: true, type: Array a.action do |global_options,options,args| app = PGit::Command::Application.new(global_options, options, args) add = PGit::Command::Add.new(app) add.execute! end end c.desc "edit a command" c.command :edit do |a| accept(Array) do |value| value.split(',').map {|item| item.strip } end a.desc "name of the command" a.arg_name "new_command_name" a.flag :n, :name, required: true a.desc "steps of the command, delimited by commas" a.arg_name "steps" a.flag :s, :steps, required: true, type: Array a.action do |global_options,options,args| app = PGit::Command::Application.new(global_options, options, args) edit = PGit::Command::Edit.new(app) edit.execute! end end c.desc "remove a command" c.command :rm do |a| accept(Array) do |value| value.split(',').map {|item| item.strip } end a.desc "name of the command" a.arg_name "new_command_name" a.flag :n, :name, required: true a.action do |global_options,options,args| app = PGit::Command::Application.new(global_options, options, args) remove = PGit::Command::Remove.new(app) remove.execute! end end end desc "Show the status of the story being worked on" command :status do |c| c.action do |global_options,options,args| status = PGit::Status.new(global_options,options,args) status.execute! end end desc "Installs the pgit configuration file" command :install do |c| c.action do |global_options,options,args| completer = PGit::Installer::BashAutoCompletion.new(global_options, options, args) completer.write_completer_file completer.source_completer_from_bashrc end end # desc 'Start, finish, etc. Pivotal Tracker story branches' desc 'Start Pivotal Tracker story branches' long_desc "Makes a cURL request to Pivotal Tracker to fetch the story, based on the given story id, parses the title, appends it with the story id. It then creates a branch name with that parsed title and does a `git checkout` to it. " command :story_branch do |c| c.desc "Parses the title of the given Pivotal Tracker story,\n" + " makes the branch name, and does a checkout" c.arg_name 'STORY_ID' c.flag :s, :start c.action do |global_options,options,args| PGit::StoryBranch::Application.new(global_options, options, args) end end desc 'Deal with iterations' command :branch do |c| c.desc "The scope of the iteration. Valid scopes are 'current', 'current_backlog', 'backlog', and 'done'" c.default_value :current_backlog c.flag :s, :scope c.action do |global_options,options,args| bilateral_story = PGit::Bilateral::Story.new(options) bilateral_story.execute! end end desc 'Initializes configuration file' arg_name 'path/to/config_file' pre do |global,command,options,args| # Pre logic here # Return true to proceed; false to abort and not call the # chosen command # Use skips_pre before a command to skip this block # on that command only # $trace = true if global.fetch(:trace) $trace = true if global.fetch(:trace) Rainbow.enabled = global.fetch(:color) true end post do |global,command,options,args| # Post logic here # Use skips_post before a command to skip this # block on that command only end on_error do |exception| # Error logic here # return false to skip default error handling warn Rainbow("error: #{exception}").color(:red) exception.backtrace.each { |e| warn Rainbow(e).color(:red) } if $trace exit 1 end exit run(ARGV)