Class: Devlogs::CLI

Inherits:
Thor
  • Object
show all
Includes:
TTYPromptHelper
Defined in:
lib/devlogs/cli.rb

Overview

The CLI devlogs CLI

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TTYPromptHelper

#build_select_prompt

Class Method Details

.exit_on_failure?Boolean

Returns exit with non zero status when an exception occurs

Returns:

  • (Boolean)


21
22
23
# File 'lib/devlogs/cli.rb', line 21

def self.exit_on_failure?
  true
end

Instance Method Details

#initObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/devlogs/cli.rb', line 39

def init
  puts "Creating devlogs repository"

  Repository::Initializer.run(
    {
      force: options.force?,
      dirpath: options.dirpath
    }
  )

  puts "Created devlogs repository"
end

#lastObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/devlogs/cli.rb', line 57

def last
  puts "Reading last entry"
  last_entry = repo.ls.first

  if options.open?
    Editor.open(last_entry)
  else
    puts File.read(last_entry)
  end
end

#lsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/devlogs/cli.rb', line 118

def ls
  entries = repo.ls

  if entries.empty?
    puts "No logs present in this repository"
    exit 0
  end

  # Use the file names as visible keys for the prompt
  entry_names = entries.map { |e| File.basename(e) }

  # Build the TTY:Prompt
  result = build_select_prompt(data: entry_names, text: "Select a log entry...")

  # Open in paging program
  Pager.open(entries[result])
end

#ls_issuesObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/devlogs/cli.rb', line 96

def ls_issues
  issues = repo.ls_issues

  if issues.empty?
    puts "No issues present in this repository"
    exit 0
  end

  # Use the file names as visible keys for the prompt
  issue_names = issues.map { |e| File.basename(e) }

  # Build the TTY:Prompt
  result = build_select_prompt(data: issue_names, text: "Select an issue issue...")

  # Open in paging program
  Pager.open(issues[result])
end

#newObject



74
75
76
77
78
79
# File 'lib/devlogs/cli.rb', line 74

def new
  puts "Creating new entry..."
  repo.create

  repo.sync
end

#new_issueObject



87
88
89
90
# File 'lib/devlogs/cli.rb', line 87

def new_issue
  repo.create_issue
  repo.sync
end

#versionObject



29
30
31
# File 'lib/devlogs/cli.rb', line 29

def version
  puts Devlogs::VERSION
end