Class: Work::Md::Commands::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/work/md/commands/config.rb

Class Method Summary collapse

Class Method Details

.execute(_argv = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/work/md/commands/config.rb', line 8

def execute(_argv = [])
  file_name = 'config.yml'
  work_dir = ::Work::Md::Config::DEFAULT_WORK_DIR

  unless ::File.exist?("#{work_dir}/#{file_name}")
    ::FileUtils.mkdir_p(work_dir)

    ::File.open("#{work_dir}/#{file_name}", 'w+') do |f|
      f.puts('# Example configuration:')
      f.puts('#')
      f.puts('# title: Your Name')
      f.puts('# editor: vim')
      f.puts('# lang: en')
      f.puts('#')
      f.puts('title: # Title your work-md files')
      f.puts('editor: # Your default editor')
      f.puts("lang: # Only 'pt', 'en' and 'es' avaiable")
    end
  end

  ::Work::Md::File.open_in_editor(
    [file_name],
    dir: work_dir
  )
end