Class: Work::Md::Commands::Open

Inherits:
Object
  • Object
show all
Defined in:
lib/work/md/commands/open.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
33
34
35
36
37
38
39
40
# File 'lib/work/md/commands/open.rb', line 8

def execute(argv = [])
  file_paths =
    Work::Md::DateFile.list_file_paths_by_argv_query(
      argv,
      create_inexistent: true
    )

  if file_paths == []
    puts ::TTY::Box.frame(
        "message: File(s) not found!",
        **Work::Md::Cli.error_frame_style
      )

    return
  end

  Work::Md::File.open_in_editor(file_paths)
rescue
  Work::Md::Cli.help(
    ::TTY::Box.frame(
      "message: Some error occurred interpreting your command or the date sent is invalid!",
      '',
      'Usage examples:',
      '',
      'work-md o -d=1 -m=5 -y=2000 # open day 1 from month 5 and year 2000',
      'work-md o -d=1,2,3          # open day 1, 2 and 3 from the current month and year',
      'work-md o -d=1,2 -m=4       # open day 1 and 2 from month 4 and current year',
      'work-md o -d=1..10 -m=4     # open day 1 to 10 from month 4 and current year',
      'work-md o -d=1..25 -m=2 and -d=1..25 -m=2 -y=1999     # open day 1 to 25 from month 2 and current year and 1 to 25 from month 2 in 1999',
      **Work::Md::Cli.error_frame_style
    )
  )
end