Class: Bones::App::Command

Inherits:
Object show all
Defined in:
lib/bones/app/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @options = {
    :skeleton_dir => File.join(mrbones_dir, 'data'),
    :with_tasks => false,
    :verbose => false,
    :name => nil,
    :output_dir => nil
  }
  @options[:skeleton_dir] = ::Bones.path('data') unless test(?d, skeleton_dir)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/bones/app/command.rb', line 7

def options
  @options
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_dirObject

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.expand_path(path)
end

#nameObject

The project name from the command line.



40
41
42
# File 'lib/bones/app/command.rb', line 40

def name
  options[:name]
end

#output_dirObject

The output directory where files will be written.



28
29
30
# File 'lib/bones/app/command.rb', line 28

def output_dir
  options[:output_dir]
end

#repositoryObject

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 options[:repository] if options.has_key? :repository
  return IO.read(skeleton_dir).strip if skeleton_dir and test(?f, skeleton_dir)
  nil
end

#run(args) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/bones/app/command.rb', line 22

def run( args )
  raise NotImplementedError
end

#skeleton_dirObject

The directory where the project skeleton is located.



34
35
36
# File 'lib/bones/app/command.rb', line 34

def skeleton_dir
  options[:skeleton_dir]
end

#standard_optionsObject



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 standard_options
  {
    :verbose => ['-v', '--verbose', 'enable verbose output',
        lambda {
          options[:verbose] = true
        }],
    :directory => ['-d', '--directory DIRECTORY', String,
        'project directory to create', '(defaults to project_name)',
        lambda { |value|
          options[:output_dir] = value
        }],
    :skeleton => ['-s', '--skeleton NAME', String,
        'project skeleton to use',
        lambda { |value|
          path = File.join(mrbones_dir, value)
          if test(?e, path)
            options[:skeleton_dir] = path 
          elsif test(?e, value)
            options[:skeleton_dir] = value
          else
            raise ArgumentError, "Unknown skeleton '#{value}'"
          end
        }],
    :with_tasks => ['--with-tasks', 'copy rake tasks to the project folder',
        lambda {
          options[:with_tasks] = true
        }],
    :repository => ['-r', '--repository URL', String,
        'svn or git repository path', 
        lambda { |value|
          options[: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?
  options[: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?
  options[:with_tasks]
end