tldr-cli 0.1.0 → 0.2.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 +8 -0
- data/README.md +13 -19
- data/lib/tldr/cli/commands.rb +24 -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: 69d3aaf2f20daf765bd313d5dc9dc95da2a83a0c44fef218b09e549370ebb493
|
4
|
+
data.tar.gz: 93e8e3ed79d2324b6caf67475f26becffe84206ff4b021ea95bda0e6aeacb052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05a3e0db692a108529ecb6743fc108db8ef754f5f7df397ba55852e5bef4fdaf091295acc47527dc6210dd8b1bb53d32db06c4924fe58b1c1b236336f6af19f
|
7
|
+
data.tar.gz: bec29e50961368dd1237b206eacc9f93d3428d96160730e724cb7b033b540994de9ffd2a82e055dbae35f387b43b55f8d3b4dcfd143bdfeff617c648da207e9b
|
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
@@ -63,6 +63,16 @@ module TLDR
|
|
63
63
|
# desc 'list all entries in the local database'
|
64
64
|
# end
|
65
65
|
|
66
|
+
option :lang do
|
67
|
+
optional
|
68
|
+
short '-l'
|
69
|
+
long '--lang=string'
|
70
|
+
default 'en'
|
71
|
+
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
|
72
|
+
tr uk uz zh zh_TW]
|
73
|
+
desc 'select language of page to be displayed (default: en)'
|
74
|
+
end
|
75
|
+
|
66
76
|
option :platform do
|
67
77
|
optional
|
68
78
|
short '-p'
|
@@ -86,15 +96,15 @@ module TLDR
|
|
86
96
|
elsif params[:version]
|
87
97
|
version
|
88
98
|
elsif params[:query]
|
89
|
-
query =
|
90
|
-
|
99
|
+
query, lang, platform =
|
100
|
+
params.to_h.values_at(:query, :lang, :platform)
|
91
101
|
|
92
|
-
|
102
|
+
page_path = "/#{platform}/#{query}"
|
93
103
|
|
104
|
+
response = Faraday.get(remote_path(page_path, lang: lang))
|
94
105
|
return not_found unless response.success?
|
95
106
|
|
96
|
-
|
97
|
-
puts markdown
|
107
|
+
render_markdown(response.body)
|
98
108
|
else
|
99
109
|
print help
|
100
110
|
end
|
@@ -102,6 +112,10 @@ module TLDR
|
|
102
112
|
|
103
113
|
private
|
104
114
|
|
115
|
+
def render_markdown(content)
|
116
|
+
puts TTY::Markdown.parse(content, symbols: { override: { bullet: '-' } })
|
117
|
+
end
|
118
|
+
|
105
119
|
def version
|
106
120
|
puts <<~MESSAGE
|
107
121
|
tldr v#{TLDR::CLI::VERSION} (v#{TLDR::CLI::VERSION})
|
@@ -116,6 +130,11 @@ module TLDR
|
|
116
130
|
Submit new pages here: https://github.com/tldr-pages/tldr
|
117
131
|
MESSAGE
|
118
132
|
end
|
133
|
+
|
134
|
+
def remote_path(fragment, lang: 'en', relative: false)
|
135
|
+
lang = lang == 'en' ? '' : ".#{lang}"
|
136
|
+
"#{relative ? '' : URL_BASE}#{lang}#{fragment}#{URL_SUFFIX}"
|
137
|
+
end
|
119
138
|
end
|
120
139
|
end
|
121
140
|
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.2.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
|