Class: Resumer::Command::Init

Inherits:
Commander::Command
  • Object
show all
Defined in:
lib/resumer/commands/init.rb

Overview

Initialize a resume YAML file

Instance Method Summary collapse

Constructor Details

#initializeInit

Returns a new instance of Init.



9
10
11
12
13
14
15
16
# File 'lib/resumer/commands/init.rb', line 9

def initialize
  super(:init)
  @summary = 'Initialize a resume.yml file'
  @syntax = "#{Resumer::BIN} init [/path/to/resume.yml]"
  @template = File.expand_path(
    "#{File.dirname(__FILE__)}/../../../templates/default.yml"
  )
end

Instance Method Details

#ask_overrideObject



18
19
20
21
22
# File 'lib/resumer/commands/init.rb', line 18

def ask_override
  agree('Destination exists, do you want to override? [y/n]', true) do |q|
    q.responses[:not_valid] = 'Please enter "[y]es" or "[n]o".'
  end
end

#parse_dest(path) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/resumer/commands/init.rb', line 24

def parse_dest(path)
  return File.join(Dir.pwd, 'resume.yml') if path.nil?

  dest = File.expand_path(path)
  return File.join(dest, 'resume.yml') if File.directory? dest

  dest
end

#run(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/resumer/commands/init.rb', line 33

def run(*args)
  dest = parse_dest(args.first)
  override = (ask_override if File.exist? dest) || false
  return if File.exist?(dest) && !override

  FileUtils.cp @template, dest
  say "Your new resume is ready at '#{dest}'"
  say 'Good luck!'
rescue Errno => e
  say e.message
  exit e.class::Errno
end