#!/usr/bin/env ruby # vim: syn=ruby # $: << 'lib' # debug only require "cbt" require "optparse" require "term/ansicolor" class String; include Term::ANSIColor end require "dev_flow" # setup for some constants known_platforms = %w[ios android mock debug] cmd_alias = {co: 'checkout', close: 'cleanup'} # parse command line options options = {} optparse = OptionParser.new do |opt| opt.banner = "Usage: cbt [OPTIONS] COMMAND [COMPONENT,COMPONENT,...]" opt.separator "" opt.separator "Commands:" opt.separator " checkout: checkout file to workspace for development" opt.separator " build : an alias of checkout, but force require files use" opt.separator " the same platform version as the current component" opt.separator " create : create skeleton files for a component" opt.separator " diagram : create/update component relationship diagram" opt.separator " cleanup : safely delete a workspace folder" opt.separator "" opt.separator "Platforms: " + known_platforms.join(', ') opt.separator "" opt.separator "" # ------------------------ options[:components_dir] = 'components' opt.on('--components_dir DIR', 'direcctory name contains all components') do |dir| options[:components_dir] = dir end options[:workspace_dir] = 'workspaces' opt.on('-w DIR', '--workspace_dir DIR', 'direcctory for development') do |dir| options[:workspace_dir] = dir end options[:assets_dir] = 'assets' opt.on('-t DIR', '--assets_dir DIR', 'global assets directory') do |dir| options[:assets_dir] = dir end options[:config_file] = 'config/components.yml' opt.on('-c FILE', '--config_file FILE', 'specify the components definition file') do |file| options[:config_file] = file end options[:platform] = 'debug' opt.on("-p PLATFORM", "--platform PLATFORM", 'platform version for component') do |platform| raise "unknown platform #{platform}" unless known_platforms.include? platform options[:platform] = platform end options[:require_platform] = 'mock' opt.on("-r PLATFORM", "--require_platform PLATFORM", 'platform version for required components') do |rp| raise "unknown platform #{rp}" unless known_platforms.include? rp options[:require_platform] = rp end opt.on('-a', '--all', 'apply to all components') do options[:all] = true end opt.on('-v', '--verbose', 'print more messages') do options[:verbose] = true end opt.on('-f', '--force', 'create/checkout even if file exists') do options[:force] = true end opt.on('--no-consistency-check', 'checkout without check file consistency') do options[:no_consistency_check] = true end opt.on('--all-spec', 'copy spec test files from all components') do options[:all_spec] = true end opt.on('-s', '--similation', 'do not actually copy files, only show file list') do options[:simulation] = true end # restrict output for models with those tag only options[:tag] = [] opt.on('-t', '--tag TAG,LIST', 'restrict diagram for modules with those tag only') do |list| options[:tag] = list.split(/\s*,\s*/) end opt.on_tail('-h', '--help', 'Display this screen') do puts opt exit end end optparse.parse!(ARGV) command = ARGV[0] options[:component] = ARGV[1] unless command # puts "Use 'checkout' as default command" command = 'checkout' end # if the user used a short version of command command = cmd_alias[command.to_sym] if cmd_alias[command.to_sym] if command == 'build' options[:build] = true command = 'checkout' end case command when 'create' Cbt::Creator.new(options).process! when 'checkout' Cbt::Checkout.new(options).process! when 'cleanup' Cbt::Cleanup.new(options).process! when 'diagram' Cbt::Diagram.new(options).process! else raise "use one of the commands: create/checkout/build/cleanup/diagram" end