#!/bin/env ruby require 'taco/cli' begin cli = TacoCLI.new rescue TacoRc::ParseError => e puts "Parse error while reading .tacorc: #{e}" exit 1 end require 'commander/import' program :name, 'taco' program :version, '1.4.2' program :description, 'simple command line issue tracking' command :init do |c| c.syntax = 'taco init' c.summary = 'initialize a taco repo in the current directory' c.description = 'Initialize a taco Issue repository in the current working directory' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") unless args.size == 0 puts cli.init! rescue Exception => e puts "Error: #{e}" exit 1 end end end command :list do |c| c.syntax = 'taco list' c.summary = 'list all issues in the repository' c.description = 'List all taco Issues in the current repository' c.option '--sort STRING', String, 'sort results by the given attributes' c.example 'Sort Issues by Priority, Owner, and Kind', 'taco list --sort priority,owner,kind' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. unless args.all? { |arg| arg =~ /\w+:\w+/ } raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") end puts cli.list args, :sort => options.sort rescue Exception => e puts "Error: #{e}" exit 1 end end end command :new do |c| c.syntax = 'taco new [path_to_issue_template]' c.summary = 'create a new Issue' c.description = "Create a new Issue, interactively or from a template file.\n Interactive mode launches $EDITOR with an Issue template." c.example 'interactive Issue creation', 'taco new' c.example 'Issue creation from a file', 'taco new /path/to/template' c.option '--retry', nil, 'retry a failed Issue creation' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") if args.size > 1 begin puts cli.new! args, { :retry => options.retry } rescue Issue::Invalid => e raise Issue::Invalid.new("#{e.to_s}.\nYou can use the --retry option to correct this error.") end rescue Exception => e puts "Error: #{e}" exit 1 end end end command :show do |c| c.syntax = 'taco show ' c.summary = 'display details for one or more Issues' c.description = 'Display details for one or more Issues' c.example 'show Issue by id', 'taco show 9f9c52ce1ced4ace878155c3a98cced0' c.example 'show Issue by unique id fragment', 'taco show ce1ced' c.example 'show two Issues by unique id fragment', 'taco show ce1ced bc2de4' c.example 'show Issue with changelog', 'taco show --changelog 9f9c52' c.example "show all Issues with 'kind' value 'kind2'", 'taco show --all kind:kind2' c.example "show all Issues with 'kind' value 'kind2' and 'owner' value 'mike'", 'taco show --all kind:kind2 owner:mike' c.option '--changelog', nil, 'shows the changelog' c.option '--all', nil, 'show all Issues' c.action do |args, options| begin puts cli.show args, { :changelog => options.changelog, :all => options.all } rescue Exception => e puts "Error: #{e}" exit 1 end end end command :edit do |c| c.syntax = 'taco edit ' c.summary = 'edit an Issue' c.description = 'Edit details for an Issue' c.option '--retry', nil, 'retry a failed Issue edit' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") unless args.size == 1 begin puts cli.edit! args, { :retry => options.retry } rescue Issue::Invalid => e raise Issue::Invalid.new("#{e.to_s}.\nYou can use the --retry option to correct this error.") end rescue Exception => e puts "Error: #{e}" exit 1 end end end command :template do |c| c.syntax = 'taco template' c.summary = 'print the Issue template on stdout' c.description = 'Print the Issue template on stdout' c.option '--defaults', nil, 'Print the Issue template with default values' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") unless args.size == 0 puts cli.template({ :defaults => options.defaults }) rescue Exception => e puts "Error: #{e}" exit 1 end end end command :html do |c| c.syntax = 'taco html' c.summary = 'Generate an HTML buglist' c.description = 'Generate an HTML buglist from index.html.erb' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") unless args.size == 0 puts cli.html rescue Exception => e puts "Error: #{e}" exit 1 end end end command :push do |c| c.syntax = 'taco push' c.summary = 'Add, commit, and push all changes to git remote.' c.description = 'Shortcut for: git add . && git commit -a && git push' c.option '--message STRING', String, 'Override the default commit message.' c.action do |args, options| begin # FIXME: merge this kind of thing into commander: tell it how many arguments we expect. raise ArgumentError.new("Unexpected arguments: #{args.join(', ')}") unless args.size == 0 puts cli.push({ :message => options.message }) rescue Exception => e puts "Error: #{e}" exit 1 end end end