Class: Bones::App::FreezeCommand

Inherits:
Command show all
Defined in:
lib/bones/app/freeze_command.rb

Instance Attribute Summary

Attributes inherited from Command

#options

Instance Method Summary collapse

Methods inherited from Command

#copy_tasks, #initialize, #mrbones_dir, #name, #output_dir, #repository, #skeleton_dir, #standard_options, #verbose?, #with_tasks?

Constructor Details

This class inherits a constructor from Bones::App::Command

Instance Method Details

#freeze_to_repositoryObject

Freeze the project skeleton to the git or svn repository that the user passed in on the command line. This essentially creates an alias to the reposiory using the name passed in on the command line.



61
62
63
64
65
66
# File 'lib/bones/app/freeze_command.rb', line 61

def freeze_to_repository
  FileUtils.mkdir_p(File.dirname(output_dir))
  File.open(output_dir, 'w') {|fd| fd.puts repository}
  @out.puts "Project skeleton #{name.inspect} " <<
            "has been frozen to #{repository.inspect}"
end

#parse(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bones/app/freeze_command.rb', line 28

def parse( args )
  std_opts = standard_options

  opts = OptionParser.new
  opts.banner = 'Usage: bones freeze [options] [skeleton_name]'

  opts.separator ''
  opts.separator '  Freeze the project skeleton to the current Mr Bones project skeleton.'
  opts.separator '  If a name is not given, then the default name "data" will be used.'
  opts.separator '  Optionally a git or svn repository can be frozen as the project'
  opts.separator '  skeleton.'

  opts.separator ''
  opts.on(*std_opts[:repository])
  opts.on(*std_opts[:with_tasks])

  opts.separator ''
  opts.separator '  Common Options:'
  opts.on_tail( '-h', '--help', 'show this message' ) {
    @out.puts opts
    exit
  }

  # parse the command line arguments
  opts.parse! args
  options[:name] = args.empty? ? 'data' : args.join('_')
  options[:output_dir] = File.join(mrbones_dir, name)
end

#run(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bones/app/freeze_command.rb', line 7

def run( args )
  parse args

  fm = FileManager.new(
    :source => repository || ::Bones.path('data'),
    :destination => output_dir,
    :stdout => @out,
    :stderr => @err,
    :verbose => verbose?
  )

  fm.archive_destination
  return freeze_to_repository if repository

  fm.copy
  copy_tasks(File.join(output_dir, 'tasks')) if with_tasks?

  @out.puts "Project skeleton #{name.inspect} " <<
            "has been frozen to Mr Bones #{::Bones::VERSION}"
end