tldr-cli 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/tldr/cli/commands.rb +29 -2
- data/lib/tldr/cli/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc8340ef090cdcfd533ff82ad775c7ede0266eb86f8e2339413c602e5e5d56f
|
4
|
+
data.tar.gz: f7876530905c3b140c1e0496545e2152a52ac02eb238015b6591097bdca829d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95ff5d7ceb347ce99837f9c03ac552082456daf00b59759d83fb64fa981d4c8c53b22f2329a8796f3b90b30f5acdfd7fa9e8d0d72573065995df66f04a15ff93
|
7
|
+
data.tar.gz: 2a65eec38bff5e22f050c240ea21512c6c8e112e1932f3b6b73e3e0a1c00abe0ad5c35c6f806606a0ed9eee1b2241e7307a36d18b5f87cb5de4037feb77c8558
|
data/CHANGELOG.md
CHANGED
data/lib/tldr/cli/commands.rb
CHANGED
@@ -15,6 +15,9 @@ module TLDR
|
|
15
15
|
URL_SUFFIX =
|
16
16
|
ENV.fetch('TLDR_URL_SUFFIX', '.md')
|
17
17
|
|
18
|
+
LOCAL_BASE =
|
19
|
+
ENV.fetch('TLDR_LOCAL_BASE', "#{Dir.home}/.config/tldr/pages")
|
20
|
+
|
18
21
|
usage do
|
19
22
|
program 'tldr'
|
20
23
|
|
@@ -82,6 +85,15 @@ module TLDR
|
|
82
85
|
desc 'select platform, supported are linux / osx / sunos / windows / common'
|
83
86
|
end
|
84
87
|
|
88
|
+
option :source do
|
89
|
+
optional
|
90
|
+
short '-s'
|
91
|
+
long '--source=string'
|
92
|
+
default 'local'
|
93
|
+
permit %w[local remote]
|
94
|
+
desc 'select page source to be local or remote (default: local)'
|
95
|
+
end
|
96
|
+
|
85
97
|
argument :query do
|
86
98
|
arity zero_or_more
|
87
99
|
end
|
@@ -96,11 +108,17 @@ module TLDR
|
|
96
108
|
elsif params[:version]
|
97
109
|
version
|
98
110
|
elsif params[:query]
|
99
|
-
query, lang, platform =
|
100
|
-
params.to_h.values_at(:query, :lang, :platform)
|
111
|
+
query, lang, platform, source =
|
112
|
+
params.to_h.values_at(:query, :lang, :platform, :source)
|
101
113
|
|
102
114
|
page_path = "/#{platform}/#{query}"
|
103
115
|
|
116
|
+
if source == 'local' && local_page?(local_path(page_path, lang: lang))
|
117
|
+
content = File.read(local_path(page_path, lang: lang))
|
118
|
+
render_markdown(content)
|
119
|
+
return
|
120
|
+
end
|
121
|
+
|
104
122
|
response = Faraday.get(remote_path(page_path, lang: lang))
|
105
123
|
return not_found unless response.success?
|
106
124
|
|
@@ -131,6 +149,15 @@ module TLDR
|
|
131
149
|
MESSAGE
|
132
150
|
end
|
133
151
|
|
152
|
+
def local_page?(page_path)
|
153
|
+
File.exist?(page_path)
|
154
|
+
end
|
155
|
+
|
156
|
+
def local_path(fragment, lang: 'en', relative: false)
|
157
|
+
lang = lang == 'en' ? '' : ".#{lang}"
|
158
|
+
"#{relative ? '' : LOCAL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
159
|
+
end
|
160
|
+
|
134
161
|
def remote_path(fragment, lang: 'en', relative: false)
|
135
162
|
lang = lang == 'en' ? '' : ".#{lang}"
|
136
163
|
"#{relative ? '' : URL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
data/lib/tldr/cli/version.rb
CHANGED