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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a61855908c1a17de1bdf6c0eaeaa263698d2e3e0d581887b230e146c0e049078
4
- data.tar.gz: ea63efc92bdec797db099fb7e7f20c1f56aec73eb168d131cce3cea4eeb35649
3
+ metadata.gz: 69d3aaf2f20daf765bd313d5dc9dc95da2a83a0c44fef218b09e549370ebb493
4
+ data.tar.gz: 93e8e3ed79d2324b6caf67475f26becffe84206ff4b021ea95bda0e6aeacb052
5
5
  SHA512:
6
- metadata.gz: 2ea75cddc8d4a70df210069b7fff660e9f1d748a7e094a1cc07e17a8aebcbd0ddabee7d050efe86eb8855565fa35e8cc793b5799b2d0f684ab77ba40fc290c3a
7
- data.tar.gz: f6cb13f8c1ba4f4992e824db3d1d6c8322921b3fc1933ea830fc5976c7cc6a2b402cfee1e4821982542d7dd5cf1c329c8a3b6631eb32d0e35aea082b9e4ac28c
6
+ metadata.gz: c05a3e0db692a108529ecb6743fc108db8ef754f5f7df397ba55852e5bef4fdaf091295acc47527dc6210dd8b1bb53d32db06c4924fe58b1c1b236336f6af19f
7
+ data.tar.gz: bec29e50961368dd1237b206eacc9f93d3428d96160730e724cb7b033b540994de9ffd2a82e055dbae35f387b43b55f8d3b4dcfd143bdfeff617c648da207e9b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
+
1
2
  ## [Unreleased]
2
3
 
4
+
5
+ ## [0.2.0] - 2024-03-06
6
+
7
+ - Added support to page languages
8
+
3
9
  ## [0.1.0] - 2023-05-18
4
10
 
5
11
  - Initial release
12
+
13
+
data/README.md CHANGED
@@ -1,34 +1,28 @@
1
- # Tldr::Cli
1
+ # tldr-cli
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tldr/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
12
+ $ tldr [command]
13
+
14
+ Example:
15
+
16
+ $ tldr tar
26
17
 
27
- ## Development
18
+ ## Roadmap
28
19
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
 
@@ -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 = params[:query]
90
- platform = params[:platform]
99
+ query, lang, platform =
100
+ params.to_h.values_at(:query, :lang, :platform)
91
101
 
92
- response = Faraday.get("#{URL_BASE}/#{platform}/#{query}#{URL_SUFFIX}")
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
- markdown = TTY::Markdown.parse(response.body, symbols: { override: { bullet: '-' } })
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TLDR
4
4
  module CLI
5
- VERSION = "0.1.0"
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.1.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: 2023-05-18 00:00:00.000000000 Z
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.13
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