octodown 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/octodown +1 -5
- data/lib/octodown/support/file_chooser.rb +75 -25
- data/lib/octodown/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89c51bf66ccf645f30d89b02527b0d7d4f976d69
|
4
|
+
data.tar.gz: 6bf5907da675618e307c7fbb6613ea93f8f66803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 661e7500c5ab971eed08b57c2e7d4550944a850769722eaf0b3aedd8fedde103ba1c003c7c633c813c501182a2aa041744d61231350d88d4bfe974a6ad766b04
|
7
|
+
data.tar.gz: 01a6a0e86ea8626a9b2676d4f06947db7e5a31b0991d36e2fe562c7b9d9773bd028e51c0efa9b7a995322cc1d777cae98e95defac2fba0097975b4e0b98459c4
|
data/bin/octodown
CHANGED
@@ -71,16 +71,12 @@ OptionParser.new do |opts|
|
|
71
71
|
end
|
72
72
|
end.parse!
|
73
73
|
|
74
|
-
require 'tty-prompt'
|
75
|
-
|
76
|
-
TUI = TTY::Prompt.new(enable_color: true)
|
77
|
-
|
78
74
|
options[:file] = if ARGF.file == STDIN && options[:stdin]
|
79
75
|
STDIN
|
80
76
|
elsif ARGF.file != STDIN
|
81
77
|
ARGF.file
|
82
78
|
else
|
83
|
-
FileChooser.new(
|
79
|
+
Octodown::FileChooser.new(logger: options[:logger]).call
|
84
80
|
end
|
85
81
|
|
86
82
|
Octodown.call options
|
@@ -1,26 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'English'
|
2
|
+
require 'tty-prompt'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def choose_file
|
9
|
-
choices = all_markdown_files
|
10
|
-
choice = prompt.select('Which markdown file would you like to edit?', choices)
|
11
|
-
File.open(choice, 'r')
|
12
|
-
end
|
13
|
-
|
14
|
-
def abort_no_files_found!
|
15
|
-
prompt.error 'We could not find any markdown files in this folder.'
|
16
|
-
puts
|
17
|
-
prompt.error 'Try passing the file explicitly such as, i.e:'
|
18
|
-
prompt.error ' $ octodown README.md'
|
19
|
-
exit 1
|
20
|
-
end
|
4
|
+
module Octodown
|
5
|
+
class FileChooser
|
6
|
+
TUI = ::TTY::Prompt.new(enable_color: true)
|
21
7
|
|
22
|
-
|
23
|
-
extensions = %w[markdown
|
8
|
+
EXTENSIONS = %w[markdown
|
24
9
|
mdown
|
25
10
|
mkdn
|
26
11
|
md
|
@@ -29,12 +14,77 @@ class FileChooser
|
|
29
14
|
mdtxt
|
30
15
|
mdtext
|
31
16
|
text
|
32
|
-
Rmd]
|
17
|
+
Rmd].freeze
|
18
|
+
|
19
|
+
class MarkdownFileList
|
20
|
+
class Git
|
21
|
+
def call
|
22
|
+
ext_args = EXTENSIONS.map { |ext| "**/*.#{ext} *.#{ext}" }.join(' ')
|
23
|
+
`git ls-files --cached --others -z #{ext_args}`.split("\x0").uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def runnable?
|
27
|
+
`git rev-parse --is-inside-work-tree`
|
28
|
+
$CHILD_STATUS.success?
|
29
|
+
rescue StandardError
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Glob
|
35
|
+
def call
|
36
|
+
Dir.glob "*.{#{EXTENSIONS.join(',')}}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def runnable?
|
40
|
+
true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader :logger
|
45
|
+
|
46
|
+
def initialize(logger)
|
47
|
+
@logger = logger
|
48
|
+
end
|
49
|
+
|
50
|
+
def call
|
51
|
+
logger.debug("File choose strategy: #{winning_strategy.class.name}")
|
52
|
+
winning_strategy.call
|
53
|
+
end
|
54
|
+
|
55
|
+
def winning_strategy
|
56
|
+
strats = [Git.new, Glob.new]
|
57
|
+
@winning_strategy ||= strats.find(&:runnable?)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_reader :prompt, :logger
|
62
|
+
|
63
|
+
def initialize(logger:)
|
64
|
+
@logger = logger
|
65
|
+
@prompt = TUI
|
66
|
+
end
|
67
|
+
|
68
|
+
def call
|
69
|
+
choices = all_markdown_files
|
70
|
+
choice = prompt.select('Which file would you like to edit?', choices)
|
71
|
+
File.open(choice, 'r')
|
72
|
+
end
|
73
|
+
|
74
|
+
def abort_no_files_found!
|
75
|
+
prompt.error 'We could not find any markdown files in this folder.'
|
76
|
+
puts
|
77
|
+
prompt.error 'Try passing the file explicitly such as, i.e:'
|
78
|
+
prompt.error ' $ octodown README.md'
|
79
|
+
exit 1
|
80
|
+
end
|
33
81
|
|
34
|
-
|
82
|
+
def all_markdown_files
|
83
|
+
choices = MarkdownFileList.new(logger).call
|
35
84
|
|
36
|
-
|
85
|
+
abort_no_files_found! if choices.empty?
|
37
86
|
|
38
|
-
|
87
|
+
choices.sort_by! { |c| c.split(File::SEPARATOR).length }
|
88
|
+
end
|
39
89
|
end
|
40
90
|
end
|
data/lib/octodown/version.rb
CHANGED