#!/usr/bin/env ruby # vim: syn=ruby $: << 'lib' # debug only require "optparse" require "term/ansicolor" class String; include Term::ANSIColor end require "dev_flow" options = {} optparse = OptionParser.new do |opts| opts.banner = "Usage: dw [options] [command]" opts.separator "" opts.separator "Commands:" opts.separator " [info] : show list of tasks" opts.separator " switch : show list of tasks, and tasks can swith to" opts.separator " switch [branch]: directly switch to a branch" opts.separator " s [branch]: alias of switch" opts.separator " update-roadmap : on develop branch, update the roadmap file" opts.separator " ur : alias of update-roadmap" opts.separator " progress : change the task progress to percentage (0-99)" opts.separator " p : alias of progress" opts.separator " complete : complete a task, raise progress to 99" opts.separator " close : close the task as a leader" opts.separator " release : close a release task" opts.separator " clean[up] : delete local branches that already completed" opts.separator " gantt : create gantt chart html files under docs folder" opts.separator "" opts.separator "Options:" options[:roadmap] = 'ROADMAP' # the roadmap file opts.on('-r FILE', '--roadmap FILE', 'use an other roadmap file') do |roadmap| options[:roadmap] = roadmap end options[:local_config] = '.dev_flow' opts.on('-l FILE', '--local-config FILE', 'use an other local configuration file') do |lc| options[:local_config] = lc end options[:members_file] = 'members.yml' if File.exists? ('members.yml') options[:members_file] = 'config/members.yml' if File.exists? ('config/members.yml') opts.on('-m FILE', '--members_file FILE', 'use an other members file') do |mf| options[:members_file] = mf raise "the specified members file #{mf} is not exists." unless File.exists? mf end opts.on('-o', '--offline', 'do not use remote git server') do options[:offline] = true end options[:docs] = 'docs' opts.on('-d DIR', '--docs DIR', 'document directory for gantt chart') do |dir| options[:docs] = dir end opts.on('-v', '--verbose', 'print more messages') do options[:verbose] = true end opts.on_tail('-h', '--help', 'Display this screen') do puts opts exit end end optparse.parse!(ARGV) # determine the command command = ARGV[0] || 'info' cmd_alias = {'pg' => 'progress', 'update-roadmap' => 'ur', 'clean' => 'cleanup', 's' => 'switch'} command = cmd_alias[command] if cmd_alias[command] if %w[info init complete progress close release ur update-roadmap cleanup clean switch gantt tm timer].include? command options[:command] = command else puts "Unknown command #{command}".red exit end unless File.exists? (options[:roadmap]) puts "No roadmap file (#{options[:roadmap]}) found, can not continue.".red exit end # enter init mode unless .dev_flow file exists unless command == 'init' unless File.exists? (options[:local_config]) puts "Initializing your environment ... " DevFlow.invoke!(options, 'init') end end # release is just a alias of command close buth with a option flag set if command == 'release' options[:release] = true command = 'close' end command = 'timer' if command == 'tm' if command == 'switch' options[:switch] = true options[:branch] = ARGV[1] command = 'info' end DevFlow.invoke!(options, command)