class Bones::App::Command
Attributes
config[R]
stderr[R]
stdout[R]
Public Class Methods
inherited( other )
click to toggle source
# File lib/bones/app/command.rb, line 208 def self.inherited( other ) other.extend ClassMethods end
new( opts = {} )
click to toggle source
# File lib/bones/app/command.rb, line 14 def initialize( opts = {} ) @stdout = opts[:stdout] || $stdout @stderr = opts[:stderr] || $stderr @config = { :skeleton_dir => File.join(mrbones_dir, DEFAULT_SKELETON), :verbose => false, :name => nil, :output_dir => nil, } @config[:skeleton_dir] = ::Bones.path(DEFAULT_SKELETON) unless test(?d, skeleton_dir) end
standard_options()
click to toggle source
Returns a hash of the standard options that can be used for individual commadns.
# File lib/bones/app/command.rb, line 137 def self.standard_options @standard_options ||= { :verbose => ['-v', '--verbose', 'Enable verbose output.', lambda { |_| config[:verbose] = true }], :directory => ['-d', '--directory DIRECTORY', String, 'Project directory to create.', '(defaults to project_name)', lambda { |value| config[:output_dir] = value }], :skeleton => ['-s', '--skeleton NAME', String, 'Project skeleton to use.', lambda { |value| path = File.join(mrbones_dir, value) if test(?e, value) config[:skeleton_dir] = value elsif test(?e, path) config[:skeleton_dir] = path else raise ArgumentError, "Unknown skeleton '#{value}'." end }], :repository => ['-r', '--repository URL', String, 'svn or git repository path.', lambda { |value| config[:repository] = value }], :colorize => ['-c', '--color', '--no-color', 'Colorize output', lambda { |value| Bones.config.colorize = value }] } end
Public Instance Methods
in_directory( dir ) { || ... }
click to toggle source
Run a block of code in the given directory.
# File lib/bones/app/command.rb, line 74 def in_directory( dir ) pwd = File.expand_path(FileUtils.pwd) FileUtils.cd dir yield ensure FileUtils.cd pwd end
mrbones_dir()
click to toggle source
Returns the '.mrbones' resource directory in the user's home directory.
# File lib/bones/app/command.rb, line 65 def mrbones_dir return @mrbones_dir if defined? @mrbones_dir path = File.join(::Bones::HOME, '.mrbones') @mrbones_dir = File.expand_path(path) end
name()
click to toggle source
The project name from the command line.
# File lib/bones/app/command.rb, line 45 def name @config[:name] end
output_dir()
click to toggle source
The output directory where files will be written.
# File lib/bones/app/command.rb, line 33 def output_dir @config[:output_dir] end
parse( args )
click to toggle source
# File lib/bones/app/command.rb, line 90 def parse( args ) opts = OptionParser.new opts.banner = 'NAME' opts.separator " bones v#{::Bones.version}" opts.separator '' if self.class.synopsis opts.separator 'SYNOPSIS' self.class.synopsis.split("\n").each { |line| opts.separator " #{line.strip}" } opts.separator '' end if self.class.description opts.separator 'DESCRIPTION' self.class.description.split("\n").each { |line| opts.separator " #{line.strip}" } opts.separator '' end if self.class.options and not self.class.options.empty? opts.separator 'PARAMETERS' self.class.options.each { |option| case option when Array option << method(option.pop) if option.last =~ /^__/ opts.on(*option) when String opts.separator(" #{option.strip}") else opts.separator('') end } opts.separator '' end opts.separator ' Common Options:' opts.on_tail( '-h', '--help', 'show this message' ) { stdout.puts opts exit } opts.on_tail '' opts.parse! args return opts end
repository()
click to toggle source
A git or svn repository URL from the command line.
# File lib/bones/app/command.rb, line 51 def repository return @config[:repository] if @config.has_key? :repository return IO.read(skeleton_dir).strip if skeleton_dir and test(?f, skeleton_dir) nil end
run( args )
click to toggle source
# File lib/bones/app/command.rb, line 27 def run( args ) raise NotImplementedError end
skeleton_dir()
click to toggle source
The directory where the project skeleton is located.
# File lib/bones/app/command.rb, line 39 def skeleton_dir @config[:skeleton_dir] end
standard_options()
click to toggle source
# File lib/bones/app/command.rb, line 84 def standard_options Command.standard_options end
verbose?()
click to toggle source
Returns true
if the user has requested verbose messages.
# File lib/bones/app/command.rb, line 59 def verbose? @config[:verbose] end