Class: WorkMd::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



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

def execute(_argv = [])
  file_name = 'config.yml'
  work_dir = ::WorkMd::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

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