Class: Bones::App::Command
Direct Known Subclasses
CreateCommand, FreezeCommand, InfoCommand, UnfreezeCommand, UpdateCommand
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #copy_tasks(to) ⇒ Object
-
#initialize(out = STDOUT, err = STDERR) ⇒ Command
constructor
A new instance of Command.
-
#mrbones_dir ⇒ Object
Returns the .bones resource directory in the user’s home directory.
-
#name ⇒ Object
The project name from the command line.
-
#output_dir ⇒ Object
The output directory where files will be written.
-
#repository ⇒ Object
A git or svn repository URL from the command line.
- #run(args) ⇒ Object
-
#skeleton_dir ⇒ Object
The directory where the project skeleton is located.
- #standard_options ⇒ Object
-
#verbose? ⇒ Boolean
Returns
trueif the user has requested verbose messages. -
#with_tasks? ⇒ Boolean
Returns
trueif we are going to copy the Mr Bones tasks into the destination directory.
Constructor Details
#initialize(out = STDOUT, err = STDERR) ⇒ Command
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bones/app/command.rb', line 9 def initialize( out = STDOUT, err = STDERR ) @out = out @err = err = { :skeleton_dir => File.join(mrbones_dir, 'data'), :with_tasks => false, :verbose => false, :name => nil, :output_dir => nil } [:skeleton_dir] = ::Bones.path('data') unless test(?d, skeleton_dir) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/bones/app/command.rb', line 7 def end |
Instance Method Details
#copy_tasks(to) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bones/app/command.rb', line 61 def copy_tasks( to ) fm = FileManager.new( :source => ::Bones.path(%w[lib bones tasks]), :destination => to, :stdout => @out, :stderr => @err, :verbose => verbose? ) fm.archive_destination fm.copy end |
#mrbones_dir ⇒ Object
Returns the .bones resource directory in the user’s home directory.
81 82 83 84 85 86 |
# File 'lib/bones/app/command.rb', line 81 def mrbones_dir return @mrbones_dir if defined? @mrbones_dir path = File.join(::Bones::HOME, '.mrbones') @mrbones_dir = File.(path) end |
#name ⇒ Object
The project name from the command line.
40 41 42 |
# File 'lib/bones/app/command.rb', line 40 def name [:name] end |
#output_dir ⇒ Object
The output directory where files will be written.
28 29 30 |
# File 'lib/bones/app/command.rb', line 28 def output_dir [:output_dir] end |
#repository ⇒ Object
A git or svn repository URL from the command line.
46 47 48 49 50 |
# File 'lib/bones/app/command.rb', line 46 def repository return [:repository] if .has_key? :repository return IO.read(skeleton_dir).strip if skeleton_dir and test(?f, skeleton_dir) nil end |
#run(args) ⇒ Object
22 23 24 |
# File 'lib/bones/app/command.rb', line 22 def run( args ) raise NotImplementedError end |
#skeleton_dir ⇒ Object
The directory where the project skeleton is located.
34 35 36 |
# File 'lib/bones/app/command.rb', line 34 def skeleton_dir [:skeleton_dir] end |
#standard_options ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bones/app/command.rb', line 90 def { :verbose => ['-v', '--verbose', 'enable verbose output', lambda { [:verbose] = true }], :directory => ['-d', '--directory DIRECTORY', String, 'project directory to create', '(defaults to project_name)', lambda { |value| [:output_dir] = value }], :skeleton => ['-s', '--skeleton NAME', String, 'project skeleton to use', lambda { |value| path = File.join(mrbones_dir, value) if test(?e, path) [:skeleton_dir] = path elsif test(?e, value) [:skeleton_dir] = value else raise ArgumentError, "Unknown skeleton '#{value}'" end }], :with_tasks => ['--with-tasks', 'copy rake tasks to the project folder', lambda { [:with_tasks] = true }], :repository => ['-r', '--repository URL', String, 'svn or git repository path', lambda { |value| [:repository] = value }] } end |
#verbose? ⇒ Boolean
Returns true if the user has requested verbose messages.
75 76 77 |
# File 'lib/bones/app/command.rb', line 75 def verbose? [:verbose] end |
#with_tasks? ⇒ Boolean
Returns true if we are going to copy the Mr Bones tasks into the destination directory. Normally this will return false.
55 56 57 |
# File 'lib/bones/app/command.rb', line 55 def with_tasks? [:with_tasks] end |