Class: Zet::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/zet/cli.rb

Overview

CLI class is responsible for handling command-line arguments.

Instance Method Summary collapse

Instance Method Details

#run(args = []) ⇒ Object

CLI is used when running zet from command line (check bin/zet) file.



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
# File 'lib/zet/cli.rb', line 13

def run(args = [])
  if args.first == "note"
    require "fileutils"

    if Dir.exists?("notes")
      note_name = args[1]

      if note_name.nil?
        puts "Provide a name of your note, please"
      else
        note_file = note_file(note_name)

        if File.exists?(note_file)
          puts "This file already exists: #{note_file}! 🙀"
        else
          File.open(note_file, "w") do |file|
            template = File.read(File.join(Dir.pwd, "note_template.md"))
            template.gsub!("# HEADLINE", "# #{note_name}")

            file.puts(template)
          end

          system `code .`
          system `code #{note_file}`
        end
      end
    else
      puts "Hm, I don't see the \"notes\" folder 🤔"
    end

    0
  else
    puts "Hm, I don't know this command 🤔"
  end
end