devlogs 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ee70029616eb23078cfe60734052a855642617338f776543da002c18986cfad
4
- data.tar.gz: 8169a90b74e0524f6b9b0ebdb786ff0fb1df38e8d59c7d6bbdbbce7936d037d5
3
+ metadata.gz: 2023b8563770781f9708368975e70b713ec937df3331461096841e4f0fbd03a3
4
+ data.tar.gz: b1e7b12bac7c07aede0fa9dc8e8daca29db668e256c7a73067bc1f56993cad58
5
5
  SHA512:
6
- metadata.gz: 3aba32f26e6905b876ad6e0777a86d29abfe1ea0642180fe1320ee82b20cc3a8efd2e22088d3b469149f920fa12808166ee7572b1f2207337afbf146bbac38cc
7
- data.tar.gz: 9fa406dae78b034c22c9db6f992e00a0255c920bb569f68fb4c5a20a295df8bcab8fad4f7f58f1d8a4f0870e05025f0d7b7c135bd50feea06e5b31ccf5b62fcf
6
+ metadata.gz: 88c3a1909b19c35619abcaabd5815843ccb334362f2a1d5a8be7efb9f82fc64be9c43f51a1b0c76be012ef043b4a1b66bc0a4643ca2cb248ccafb3ee8a4b9fb3
7
+ data.tar.gz: 925757b3d644479dc402f2c17a762a349a9eb8b5dda7a75ecb88ec71e9712933b1fd223d239164ce4a24b8e0864040ad51c1a5f78ccce42535b1599f3b5ebfd3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devlogs (0.2.0)
4
+ devlogs (0.3.1)
5
5
  rsync (~> 1.0, >= 1.0.9)
6
6
  thor (~> 1.2.1)
7
7
  tty-prompt (~> 0.23.1)
data/Makefile ADDED
@@ -0,0 +1,16 @@
1
+ PROJECT=devlogs
2
+
3
+ console:
4
+ @bundle exec bin/console
5
+
6
+ setup:
7
+ @bundle exec bin/setup
8
+
9
+ install:
10
+ @bundle exec rake install
11
+
12
+ release:
13
+ @bundle exec rake release
14
+
15
+ release.gh:
16
+ @gh release create
data/lib/devlogs/cli.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require_relative "version"
4
4
  require_relative "repository"
5
5
  require_relative "editor"
6
+ require_relative "pager"
7
+ require_relative "prompt_utils"
6
8
  require "thor"
7
9
 
8
10
  module Devlogs
@@ -10,6 +12,8 @@ module Devlogs
10
12
  # The CLI devlogs CLI
11
13
  #
12
14
  class CLI < Thor
15
+ include PromptUtils
16
+
13
17
  package_name "devlogs"
14
18
 
15
19
  # Returns exit with non zero status when an exception occurs
@@ -68,6 +72,23 @@ module Devlogs
68
72
  repo.sync
69
73
  end
70
74
 
75
+ #
76
+ # Lists repository logs
77
+ #
78
+ desc "ls", "Lists the repository logs and allows you to select"
79
+ def ls
80
+ entries = repo.ls
81
+
82
+ # Use the file names as visible keys for the prompt
83
+ entry_names = entries.map { |e| File.basename(e) }
84
+
85
+ # Build the TTY:Prompt
86
+ result = build_select_prompt(data: entry_names, text: "Select a log entry...")
87
+
88
+ # Open in paging program
89
+ Pager.open(entries[result])
90
+ end
91
+
71
92
  private
72
93
 
73
94
  # Helper method for repository loading
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "./executable.rb"
4
+
3
5
  # Wrapper for terminal editor
4
- class Editor
6
+ class Editor < Executable
5
7
  def initialize
6
8
  @program = ENV["EDITOR"]
7
9
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Executable
4
+ def initialize
5
+ raise NotImplementedError, "Abstract class"
6
+ end
7
+
8
+ # Opens the file contained at the path
9
+ def open(path)
10
+ command = "#{@program} #{path}"
11
+
12
+ system command
13
+ end
14
+
15
+ class << self
16
+ # Opens the file at +path+ using system editor
17
+ def open(path)
18
+ session = new
19
+
20
+ session.open(path)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wrapper for terminal reader
4
+ require_relative "./executable.rb"
5
+
6
+ # Wrapper for terminal pager
7
+ class Pager < Executable
8
+ def initialize
9
+ @program = ENV["PAGER"]
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-prompt"
4
+
5
+ #
6
+ # Utility module for tty-prompt library
7
+ #
8
+ module PromptUtils
9
+ #
10
+ # Builds a basic select prompt using the provided data
11
+ #
12
+ # @param data [Array<String>]
13
+ #
14
+ # @returns String
15
+ #
16
+ def build_select_prompt(data:, text:)
17
+ ttyprompt = TTY::Prompt.new
18
+
19
+ ttyprompt.select(text) do |menu|
20
+ data.each_with_index do |d, index|
21
+ menu.choice d, index
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devlogs
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devlogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aquaflamingo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-27 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsync
@@ -86,6 +86,7 @@ files:
86
86
  - Gemfile
87
87
  - Gemfile.lock
88
88
  - LICENSE.txt
89
+ - Makefile
89
90
  - README.md
90
91
  - Rakefile
91
92
  - bin/console
@@ -96,6 +97,9 @@ files:
96
97
  - lib/devlogs.rb
97
98
  - lib/devlogs/cli.rb
98
99
  - lib/devlogs/editor.rb
100
+ - lib/devlogs/executable.rb
101
+ - lib/devlogs/pager.rb
102
+ - lib/devlogs/prompt_utils.rb
99
103
  - lib/devlogs/repository.rb
100
104
  - lib/devlogs/version.rb
101
105
  homepage: http://github.com/aquaflamingo/devlogs