Class: Memo::Cli::Command::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/memo/cli/command/setup.rb

Instance Method Summary collapse

Constructor Details

#initialize(_, os: Memo::OS.new) ⇒ Setup

Returns a new instance of Setup.



5
6
7
8
9
10
11
# File 'lib/memo/cli/command/setup.rb', line 5

def initialize(
  _,
  os: Memo::OS.new
)
  @os = os
  @config = Memo::Config.new
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/memo/cli/command/setup.rb', line 13

def call
  toml = <<~TOML
    [config]
    # ext = "md"
    # root = "~/.memo"
    # editor = "vim"
    # preview = "bat"
    # fuzzy_finder = "fzf --preview 'bat --color=always {}'"
    # default_filename = "memo"
    # default_namespace = "mymemo"

    [namespace_alias]
    # p1 = "project1"

    [command_alias]
    # ep1 = "edit memo -n project1"
  TOML

  if ::File.exist? @config.path
    puts "WARNING: config file already exists"
    puts
    print "reset config? (y/n) "
    ans = STDIN.gets.chomp
    if ans != "y"
      puts "aborted"
      return
    end
  end

  @os.write @config.path, toml

  puts
  puts <<~TEXT
    Create config file to #{@config.path}
    You can edit by `$ memo config`
  TEXT
end