tldr-cli 0.1.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 +11 -0
- data/README.md +13 -19
- data/lib/tldr/cli/commands.rb +51 -5
- data/lib/tldr/cli/version.rb +1 -1
- data/new.patch +103 -0
- metadata +4 -3
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/README.md
CHANGED
@@ -1,34 +1,28 @@
|
|
1
|
-
#
|
1
|
+
# tldr-cli
|
2
2
|
|
3
|
-
|
3
|
+
This is a simple and tiny tldr-pages client write using Ruby that works well.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'tldr-cli'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
8
|
$ gem install tldr-cli
|
22
9
|
|
23
10
|
## Usage
|
24
11
|
|
25
|
-
|
12
|
+
$ tldr [command]
|
13
|
+
|
14
|
+
Example:
|
15
|
+
|
16
|
+
$ tldr tar
|
26
17
|
|
27
|
-
##
|
18
|
+
## Roadmap
|
28
19
|
|
29
|
-
|
20
|
+
- [x] basic cli interface
|
21
|
+
- [x] tldr-pages markdown content fetch
|
22
|
+
- [x] tldr-pages markdown parsing and presentation
|
23
|
+
- [ ] implement content caching
|
24
|
+
- [ ] content local cache update
|
30
25
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
26
|
|
33
27
|
## Contributing
|
34
28
|
|
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
|
|
@@ -63,6 +66,16 @@ module TLDR
|
|
63
66
|
# desc 'list all entries in the local database'
|
64
67
|
# end
|
65
68
|
|
69
|
+
option :lang do
|
70
|
+
optional
|
71
|
+
short '-l'
|
72
|
+
long '--lang=string'
|
73
|
+
default 'en'
|
74
|
+
permit %w[ar bn bs ca cs da de en es fa fi fr hi id it ja ko lo ml ne nl no pl pt_BR pt_PT ro ru sh sr sv ta th
|
75
|
+
tr uk uz zh zh_TW]
|
76
|
+
desc 'select language of page to be displayed (default: en)'
|
77
|
+
end
|
78
|
+
|
66
79
|
option :platform do
|
67
80
|
optional
|
68
81
|
short '-p'
|
@@ -72,6 +85,15 @@ module TLDR
|
|
72
85
|
desc 'select platform, supported are linux / osx / sunos / windows / common'
|
73
86
|
end
|
74
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
|
+
|
75
97
|
argument :query do
|
76
98
|
arity zero_or_more
|
77
99
|
end
|
@@ -86,15 +108,21 @@ module TLDR
|
|
86
108
|
elsif params[:version]
|
87
109
|
version
|
88
110
|
elsif params[:query]
|
89
|
-
query =
|
90
|
-
|
111
|
+
query, lang, platform, source =
|
112
|
+
params.to_h.values_at(:query, :lang, :platform, :source)
|
113
|
+
|
114
|
+
page_path = "/#{platform}/#{query}"
|
91
115
|
|
92
|
-
|
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
|
93
121
|
|
122
|
+
response = Faraday.get(remote_path(page_path, lang: lang))
|
94
123
|
return not_found unless response.success?
|
95
124
|
|
96
|
-
|
97
|
-
puts markdown
|
125
|
+
render_markdown(response.body)
|
98
126
|
else
|
99
127
|
print help
|
100
128
|
end
|
@@ -102,6 +130,10 @@ module TLDR
|
|
102
130
|
|
103
131
|
private
|
104
132
|
|
133
|
+
def render_markdown(content)
|
134
|
+
puts TTY::Markdown.parse(content, symbols: { override: { bullet: '-' } })
|
135
|
+
end
|
136
|
+
|
105
137
|
def version
|
106
138
|
puts <<~MESSAGE
|
107
139
|
tldr v#{TLDR::CLI::VERSION} (v#{TLDR::CLI::VERSION})
|
@@ -116,6 +148,20 @@ module TLDR
|
|
116
148
|
Submit new pages here: https://github.com/tldr-pages/tldr
|
117
149
|
MESSAGE
|
118
150
|
end
|
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
|
+
|
161
|
+
def remote_path(fragment, lang: 'en', relative: false)
|
162
|
+
lang = lang == 'en' ? '' : ".#{lang}"
|
163
|
+
"#{relative ? '' : URL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
164
|
+
end
|
119
165
|
end
|
120
166
|
end
|
121
167
|
end
|
data/lib/tldr/cli/version.rb
CHANGED
data/new.patch
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
lib/tldr/cli/commands.rb | 57 +++++++++++++++++++++++++++++++++++++++++++-----
|
2
|
+
1 file changed, 52 insertions(+), 5 deletions(-)
|
3
|
+
|
4
|
+
diff --git a/lib/tldr/cli/commands.rb b/lib/tldr/cli/commands.rb
|
5
|
+
index c9aea38..8998696 100644
|
6
|
+
--- a/lib/tldr/cli/commands.rb
|
7
|
+
+++ b/lib/tldr/cli/commands.rb
|
8
|
+
@@ -15,6 +15,9 @@ module TLDR
|
9
|
+
URL_SUFFIX =
|
10
|
+
ENV.fetch('TLDR_URL_SUFFIX', '.md')
|
11
|
+
|
12
|
+
+ LOCAL_BASE =
|
13
|
+
+ ENV.fetch('TLDR_LOCAL_BASE', "#{Dir.home}/.config/tldr/pages")
|
14
|
+
+
|
15
|
+
usage do
|
16
|
+
program 'tldr'
|
17
|
+
|
18
|
+
@@ -63,6 +66,25 @@ module TLDR
|
19
|
+
# desc 'list all entries in the local database'
|
20
|
+
# end
|
21
|
+
|
22
|
+
+ option :lang do
|
23
|
+
+ optional
|
24
|
+
+ short '-l'
|
25
|
+
+ long '--lang=string'
|
26
|
+
+ default 'en'
|
27
|
+
+ permit %w[ar bn bs ca cs da de en es fa fi fr hi id it ja ko lo ml ne nl no pl pt_BR pt_PT ro ru sh sr sv ta th tr uk uz zh zh_TW]
|
28
|
+
+ desc 'select language of page to be displayed (default: en)'
|
29
|
+
+ end
|
30
|
+
+
|
31
|
+
+ option :source do
|
32
|
+
+ optional
|
33
|
+
+ short '-s'
|
34
|
+
+ long '--source=string'
|
35
|
+
+ default 'local'
|
36
|
+
+ permit %w[local remote]
|
37
|
+
+ desc 'select page source to be local or remote (default: local)'
|
38
|
+
+ end
|
39
|
+
+
|
40
|
+
+
|
41
|
+
option :platform do
|
42
|
+
optional
|
43
|
+
short '-p'
|
44
|
+
@@ -86,15 +108,22 @@ module TLDR
|
45
|
+
elsif params[:version]
|
46
|
+
version
|
47
|
+
elsif params[:query]
|
48
|
+
- query = params[:query]
|
49
|
+
- platform = params[:platform]
|
50
|
+
+ query, lang, source, platform =
|
51
|
+
+ params.to_h.values_at(:query, :lang, :source, :platform)
|
52
|
+
+
|
53
|
+
+ page_path = "/#{platform}/#{query}"
|
54
|
+
|
55
|
+
- response = Faraday.get("#{URL_BASE}/#{platform}/#{query}#{URL_SUFFIX}")
|
56
|
+
+ if source == 'local' && local_page?(local_path(page_path, lang: lang))
|
57
|
+
+ content = File.read(local_path(page_path, lang: lang))
|
58
|
+
+ render_markdown(content)
|
59
|
+
+ return
|
60
|
+
+ end
|
61
|
+
|
62
|
+
+ puts "Fetching page from #{source} source..." if
|
63
|
+
+ response = Faraday.get(remote_path(page_path, lang: lang))
|
64
|
+
return not_found unless response.success?
|
65
|
+
|
66
|
+
- markdown = TTY::Markdown.parse(response.body, symbols: { override: { bullet: '-' } })
|
67
|
+
- puts markdown
|
68
|
+
+ render_markdown(response.body)
|
69
|
+
else
|
70
|
+
print help
|
71
|
+
end
|
72
|
+
@@ -102,6 +131,10 @@ module TLDR
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
+ def render_markdown(content)
|
77
|
+
+ puts TTY::Markdown.parse(content, symbols: { override: { bullet: '-' } })
|
78
|
+
+ end
|
79
|
+
+
|
80
|
+
def version
|
81
|
+
puts <<~MESSAGE
|
82
|
+
tldr v#{TLDR::CLI::VERSION} (v#{TLDR::CLI::VERSION})
|
83
|
+
@@ -116,6 +149,20 @@ module TLDR
|
84
|
+
Submit new pages here: https://github.com/tldr-pages/tldr
|
85
|
+
MESSAGE
|
86
|
+
end
|
87
|
+
+
|
88
|
+
+ def local_path(fragment, lang: 'en', relative: false)
|
89
|
+
+ lang = lang == 'en' ? '' : ".#{lang.to_s}"
|
90
|
+
+ "#{relative ? '' : LOCAL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
91
|
+
+ end
|
92
|
+
+
|
93
|
+
+ def remote_path(fragment, lang: 'en', relative: false)
|
94
|
+
+ lang = lang == 'en' ? '' : ".#{lang.to_s}"
|
95
|
+
+ "#{relative ? '' : URL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
96
|
+
+ end
|
97
|
+
+
|
98
|
+
+ def local_page?(page_path)
|
99
|
+
+ File.exist?(page_path)
|
100
|
+
+ end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tldr-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vinciguerra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/tldr/cli.rb
|
73
73
|
- lib/tldr/cli/commands.rb
|
74
74
|
- lib/tldr/cli/version.rb
|
75
|
+
- new.patch
|
75
76
|
- sig/tldr/cli.rbs
|
76
77
|
- tldr-cli.gemspec
|
77
78
|
homepage: https://github.com/dvinciguerra/tldr-cli
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
- !ruby/object:Gem::Version
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
|
-
rubygems_version: 3.4.
|
101
|
+
rubygems_version: 3.4.22
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: A Ruby based command-line client for tldr
|