#!/usr/bin/ruby # # This file is part of CPEE-FRAMES. # # CPEE-FRAMES is free software: you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # CPEE-FRAMES is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with CPEE-FRAMES (file LICENSE in the main directory). If not, see # . curpath = __dir__ require 'rubygems' require 'optparse' require 'fileutils' require 'xml/smart' require 'yaml' require 'typhoeus' require 'stringio' def wrap(s, width=78, indent=18, extra_indent=4) #{{{ lines = [] line, s = s[0..indent-2], s[indent..-1] s.split(/\n/).each do |ss| ss.split(/[ \t]+/).each do |word| if line.size + word.size >= width lines << line line = (" " * (indent + extra_indent)) + word else line << " " << word end end lines << line if line line = (" " * (indent-1)) end return lines.join "\n" end #}}} exname = File.basename($0) ARGV.options { |opt| opt.summary_indent = ' ' * 2 opt.summary_width = 15 opt.banner = "Usage:\n#{opt.summary_indent}#{exname} new [DIR] | newui [DIR]\n" opt.on("Options:") opt.on("--help", "-h", "This text") { puts opt; exit } opt.on("") opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure.",78,18,0)) opt.on("") opt.on(wrap("newui [DIR] scaffolds css/js directors that are use by the UI into your webserver dir.")) opt.parse! } if (ARGV.length != 2) puts ARGV.options exit else command = ARGV[0] dir = ARGV[1] end if command == 'new' if !File.exists?(dir) FileUtils.cp_r(File.join(curpath,'..','server'),dir) FileUtils.mkdir(File.join(dir,'data')) rescue nil else puts 'Directory already exists.' end elsif command == 'newui' if !File.exists?(dir) FileUtils.cp_r(File.join(curpath,'..','ui'),dir) else puts 'Directory already exists.' end else puts ARGV.options end