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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69d3aaf2f20daf765bd313d5dc9dc95da2a83a0c44fef218b09e549370ebb493
4
- data.tar.gz: 93e8e3ed79d2324b6caf67475f26becffe84206ff4b021ea95bda0e6aeacb052
3
+ metadata.gz: 6bc8340ef090cdcfd533ff82ad775c7ede0266eb86f8e2339413c602e5e5d56f
4
+ data.tar.gz: f7876530905c3b140c1e0496545e2152a52ac02eb238015b6591097bdca829d6
5
5
  SHA512:
6
- metadata.gz: c05a3e0db692a108529ecb6743fc108db8ef754f5f7df397ba55852e5bef4fdaf091295acc47527dc6210dd8b1bb53d32db06c4924fe58b1c1b236336f6af19f
7
- data.tar.gz: bec29e50961368dd1237b206eacc9f93d3428d96160730e724cb7b033b540994de9ffd2a82e055dbae35f387b43b55f8d3b4dcfd143bdfeff617c648da207e9b
6
+ metadata.gz: 95ff5d7ceb347ce99837f9c03ac552082456daf00b59759d83fb64fa981d4c8c53b22f2329a8796f3b90b30f5acdfd7fa9e8d0d72573065995df66f04a15ff93
7
+ data.tar.gz: 2a65eec38bff5e22f050c240ea21512c6c8e112e1932f3b6b73e3e0a1c00abe0ad5c35c6f806606a0ed9eee1b2241e7307a36d18b5f87cb5de4037feb77c8558
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
2
  ## [Unreleased]
3
3
 
4
+ ## [0.3.0] - 2024-03-06
5
+
6
+ - Added support to personal local pages created at ~/.config/tldr/pages
4
7
 
5
8
  ## [0.2.0] - 2024-03-06
6
9
 
@@ -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}"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TLDR
4
4
  module CLI
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tldr-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra