yard-link_stdlib 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/yard/cli/link_stdlib.rb +22 -345
- data/lib/yard/cli/link_stdlib/add.rb +70 -0
- data/lib/yard/cli/link_stdlib/command_helper.rb +103 -0
- data/lib/yard/cli/link_stdlib/help.rb +72 -0
- data/lib/yard/cli/link_stdlib/list.rb +59 -0
- data/lib/yard/cli/link_stdlib/search.rb +156 -0
- data/lib/yard/cli/link_stdlib/url.rb +65 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35e1ca61be63e6ca2ec8b75762cf24cb2139e375
|
4
|
+
data.tar.gz: c5be9c26529b4fea0ebb8e32f84603090bf2b193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 374248e1ffd21df5717efc40de3dccbd7bc0ae62d804ce4acb36f84776cfa9293ea620547954d497c407ec91e040d408ca550dd831d5a375d6fcf4e2c6aca1e3
|
7
|
+
data.tar.gz: f4638c958009fbeccf3c6fedbdcac2ba14af45d21286ac6ac0988c6b94e093c1b7db7983e5a067460b1b2e8e4f96fab935f8f1615f0e0884e36b96b0abc2302d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/yard/cli/link_stdlib.rb
CHANGED
@@ -15,7 +15,12 @@ require 'yard'
|
|
15
15
|
|
16
16
|
### Project / Package ###
|
17
17
|
|
18
|
-
|
18
|
+
#### Sub-Commands ####
|
19
|
+
require_relative './link_stdlib/add'
|
20
|
+
require_relative './link_stdlib/help'
|
21
|
+
require_relative './link_stdlib/list'
|
22
|
+
require_relative './link_stdlib/search'
|
23
|
+
require_relative './link_stdlib/url'
|
19
24
|
|
20
25
|
|
21
26
|
# Namespace
|
@@ -28,357 +33,29 @@ module CLI
|
|
28
33
|
# Definitions
|
29
34
|
# =======================================================================
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def parse! *args
|
42
|
-
super( *args ).tap { after_parse_block.each &:call }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
module CommandHelper
|
48
|
-
|
49
|
-
def description
|
50
|
-
self.class::DESCRIPTION
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def usage
|
55
|
-
self.class::USAGE
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
def check_args! args, count
|
60
|
-
if args.length < count
|
61
|
-
log.error "Too few args! Expected #{ count }, given #{ args.length }"
|
62
|
-
exit false
|
63
|
-
elsif args.length > count
|
64
|
-
log.error "Too many args! Expected #{ count }, given #{ args.length }"
|
65
|
-
exit false
|
66
|
-
end
|
67
|
-
|
68
|
-
if args.length == 1 then args[ 0 ] else args end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def opts
|
73
|
-
@opts ||= {}
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
def add_header op, text = nil
|
78
|
-
op.banner = description
|
79
|
-
op.separator ''
|
80
|
-
op.separator 'Usage:'
|
81
|
-
op.separator ''
|
82
|
-
op.separator " #{ usage }"
|
83
|
-
op.separator ''
|
84
|
-
unless text.nil?
|
85
|
-
text.lines.each { |line| op.separator line }
|
86
|
-
end
|
87
|
-
op.separator ''
|
88
|
-
op.separator 'Options:'
|
89
|
-
|
90
|
-
op.on_tail( '-q', '--quiet', 'Show no warnings.' ) {
|
91
|
-
log.level = Logger::ERROR
|
92
|
-
}
|
93
|
-
|
94
|
-
op.on_tail( '--verbose', 'Show more information.') {
|
95
|
-
log.level = Logger::INFO
|
96
|
-
}
|
97
|
-
|
98
|
-
op.on_tail( '--debug', 'Show debugging information.' ) {
|
99
|
-
log.level = Logger::DEBUG
|
100
|
-
}
|
101
|
-
|
102
|
-
op.on_tail( '--backtrace', 'Show stack traces' ) {
|
103
|
-
log.show_backtraces = true
|
104
|
-
}
|
105
|
-
|
106
|
-
op.on_tail( '-h', '--help', %(You're looking at it!) ) {
|
107
|
-
log.puts op
|
108
|
-
exit true
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def add_version_opt op
|
113
|
-
# **DON'T** make missing versions by default here!
|
114
|
-
YARD::LinkStdlib::RubySource.make_missing = false
|
115
|
-
|
116
|
-
op.on(
|
117
|
-
'-v VERSION',
|
118
|
-
'--ruby-version=VERSION',
|
119
|
-
%(Set Ruby version)
|
120
|
-
) { |ruby_version|
|
121
|
-
YARD::LinkStdlib::RubyVersion.set ruby_version
|
122
|
-
# opts[ :ruby_version ] = ruby_version
|
123
|
-
}
|
124
|
-
|
125
|
-
op.on(
|
126
|
-
'--make-missing',
|
127
|
-
%(Download and make an object map if the Ruby version is not present)
|
128
|
-
) { |make_missing|
|
129
|
-
YARD::LinkStdlib::RubySource.make_missing = make_missing
|
130
|
-
# opts[ :make_missing ] = make_missing
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
end # CommandHelper
|
135
|
-
|
136
|
-
|
137
|
-
# @todo document LinkStdlib class.
|
36
|
+
# Top-level {YARD::CLI::Command} for the `yard-link_stdlib` plugin. Added under
|
37
|
+
# the name `stdlib` (see {YARD::LinkStdlib.install!}).
|
38
|
+
#
|
39
|
+
# Simply a router to the sub-commands. Like {YARD::CLI::CommandParser}, which
|
40
|
+
# handles routing for `yard`, but is not really re-usable. In addition, this
|
41
|
+
# class handles "-" → "_" conversion in sub-command names, since we have
|
42
|
+
# multi-word commands.
|
43
|
+
#
|
138
44
|
class LinkStdlib < Command
|
139
|
-
|
140
|
-
# Sub-commands
|
141
|
-
# ============================================================================
|
142
|
-
|
143
|
-
class List < Command
|
144
|
-
include CommandHelper
|
145
|
-
|
146
|
-
DESCRIPTION = "List Ruby versions"
|
147
|
-
USAGE = "yard stdlib list"
|
148
|
-
|
149
|
-
def run *args
|
150
|
-
|
151
|
-
|
152
|
-
log.puts \
|
153
|
-
YARD::LinkStdlib::ObjectMap.
|
154
|
-
all.
|
155
|
-
map { |om| om.version.to_s }.
|
156
|
-
join( "\n" )
|
157
|
-
end
|
158
|
-
end # class List
|
159
|
-
|
160
|
-
|
161
|
-
class Add < Command
|
162
|
-
|
163
|
-
include CommandHelper
|
164
|
-
|
165
|
-
DESCRIPTION = "Download version source and build object map"
|
166
|
-
USAGE = "yard stdlib add [OPTIONS] RUBY_VERSION"
|
167
|
-
|
168
|
-
def run *args
|
169
|
-
# Want to see what's going on by default here...
|
170
|
-
log.level = Logger::INFO
|
171
|
-
|
172
|
-
opts[ :force ] = false
|
173
|
-
|
174
|
-
OptionParser.new { |op|
|
175
|
-
add_header op
|
176
|
-
|
177
|
-
op.on( '-f', '--force',
|
178
|
-
%(Force building of map data when already present)
|
179
|
-
) { |force| opts[ :force ] = force }
|
180
|
-
|
181
|
-
}.parse! args
|
182
|
-
|
183
|
-
args.each do |version|
|
184
|
-
log.info "Adding object map for Ruby #{ version }..."
|
185
|
-
YARD::LinkStdlib::ObjectMap.add version, force: opts[ :force ]
|
186
|
-
end
|
187
|
-
|
188
|
-
exit true
|
189
|
-
end
|
190
|
-
|
191
|
-
end # class Add
|
192
|
-
|
193
|
-
|
194
|
-
class URL < Command
|
195
|
-
|
196
|
-
include CommandHelper
|
197
|
-
|
198
|
-
DESCRIPTION = "Print the online doc URL for a stdlib name"
|
199
|
-
USAGE = "yard stdlib url [OPTIONS] NAME"
|
200
|
-
|
201
|
-
def run *args
|
202
|
-
OptionParser.new { |op|
|
203
|
-
add_header op
|
204
|
-
add_version_opt op
|
205
|
-
}.parse! args
|
206
|
-
|
207
|
-
name = check_args! args, 1
|
208
|
-
|
209
|
-
url = YARD::LinkStdlib::ObjectMap.current.url_for name
|
210
|
-
|
211
|
-
if url.nil?
|
212
|
-
$stderr.puts "Name not found: #{ name.inspect }"
|
213
|
-
exit false
|
214
|
-
end
|
215
|
-
|
216
|
-
puts url
|
217
|
-
exit true
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
|
222
|
-
# Hooks into {YARD::LinkStdlib::ObjectMap#grep} to search for names using
|
223
|
-
# regular expressions.
|
224
|
-
#
|
225
|
-
class Search < Command
|
226
|
-
|
227
|
-
include CommandHelper
|
228
|
-
|
229
|
-
DESCRIPTION = "Find stdlib names that match Regexp patterns"
|
230
|
-
USAGE = "yard stdlib search [OPTIONS] TERMS..."
|
231
|
-
|
232
|
-
def run *args
|
233
|
-
# Default format is `:plain`
|
234
|
-
opts[ :format ] = :plain
|
235
|
-
|
236
|
-
OptionParser.new { |op|
|
237
|
-
add_header op, <<~END
|
238
|
-
Examples:
|
239
|
-
|
240
|
-
1. {Pathname} instance methods
|
241
|
-
|
242
|
-
$ yard stdlib search '^Pathname#'
|
243
|
-
|
244
|
-
2. All `#to_s` methods
|
245
|
-
|
246
|
-
$ yard stdlib search '#to_s$'
|
247
|
-
|
248
|
-
3. Print results in serialized formats.
|
249
|
-
|
250
|
-
All `#to_s` instance methods in JSON:
|
251
|
-
|
252
|
-
$ yard stdlib search --format=json '#to_s$'
|
253
|
-
|
254
|
-
Supports a short `-f` flag and first-letter formats too.
|
255
|
-
|
256
|
-
Instance methods of {Array} in YAML:
|
257
|
-
|
258
|
-
$ yard stdlib search -f y '^Array#'
|
259
|
-
END
|
260
|
-
|
261
|
-
add_version_opt op
|
262
|
-
|
263
|
-
op.on( '-u', '--urls',
|
264
|
-
%(Print doc URLs along with names)
|
265
|
-
) { |urls| opts[ :urls ] = !!urls }
|
266
|
-
|
267
|
-
op.on( '-f FORMAT', '--format=FORMAT',
|
268
|
-
%(Specify print format: (p)lain, (j)son or (y)aml)
|
269
|
-
) { |format|
|
270
|
-
opts[ :format ] = \
|
271
|
-
case format.downcase
|
272
|
-
when 'p', 'plain'
|
273
|
-
:plain
|
274
|
-
when 'j', 'json'
|
275
|
-
:json
|
276
|
-
when 'y', 'yaml'
|
277
|
-
:yaml
|
278
|
-
else
|
279
|
-
log.fatal \
|
280
|
-
%(Unknown format - expected "plain", "json" or "yaml"; ) +
|
281
|
-
%(given #{ format.inspect })
|
282
|
-
exit false
|
283
|
-
end
|
284
|
-
}
|
285
|
-
|
286
|
-
}.parse! args
|
287
|
-
|
288
|
-
if args.empty?
|
289
|
-
YARD::LinkStdlib::ObjectMap.
|
290
|
-
current.
|
291
|
-
names.
|
292
|
-
sort_by( &:downcase ).
|
293
|
-
each { |key| log.puts key }
|
294
|
-
exit true
|
295
|
-
end
|
296
|
-
|
297
|
-
terms = args.map { |arg|
|
298
|
-
begin
|
299
|
-
Regexp.new arg
|
300
|
-
rescue RegexpError => error
|
301
|
-
Regexp.new \
|
302
|
-
Regexp.escape( YARD::LinkStdlib.normalize_name( arg ) )
|
303
|
-
end
|
304
|
-
}
|
305
|
-
|
306
|
-
log.debug "Terms:\n " + terms.map( &:to_s ).join( "\n " )
|
307
|
-
|
308
|
-
names = YARD::LinkStdlib.grep *terms
|
309
|
-
|
310
|
-
results = \
|
311
|
-
if opts[ :urls ]
|
312
|
-
names.each_with_object( {} ) { |name, hash|
|
313
|
-
hash[ name ] = YARD::LinkStdlib::ObjectMap.current.url_for name
|
314
|
-
}
|
315
|
-
else
|
316
|
-
names
|
317
|
-
end
|
318
|
-
|
319
|
-
case opts[ :format ]
|
320
|
-
when :plain
|
321
|
-
results.each do |entry|
|
322
|
-
if entry.is_a? ::Array
|
323
|
-
log.puts "#{ entry[0] } <#{ entry[ 1 ]}>"
|
324
|
-
else
|
325
|
-
log.puts entry
|
326
|
-
end
|
327
|
-
end
|
328
|
-
when :json
|
329
|
-
require 'json'
|
330
|
-
log.puts JSON.pretty_generate( results )
|
331
|
-
when :yaml
|
332
|
-
require 'yaml'
|
333
|
-
log.puts YAML.dump( results )
|
334
|
-
end
|
335
|
-
|
336
|
-
exit true
|
337
|
-
end
|
338
|
-
end # class Search
|
339
|
-
|
340
|
-
|
341
|
-
class Help < Command
|
342
|
-
|
343
|
-
include CommandHelper
|
344
|
-
|
345
|
-
DESCRIPTION = "Show this message"
|
346
|
-
|
347
|
-
def run
|
348
|
-
commands = LinkStdlib.commands
|
349
|
-
log.puts <<~END
|
350
|
-
yard-link_stdlib provides linking to online Ruby docs for standard
|
351
|
-
library code objects.
|
352
|
-
|
353
|
-
Usage:
|
354
|
-
|
355
|
-
yard stdlib COMMAND... [OPTIONS] [ARGS]
|
356
|
-
|
357
|
-
Commands:
|
358
|
-
|
359
|
-
END
|
360
|
-
commands.keys.sort_by(&:to_s).each do |command_name|
|
361
|
-
command_class = commands[command_name]
|
362
|
-
next unless command_class < Command
|
363
|
-
command = command_class.new
|
364
|
-
log.puts "%-8s %s" % [command_name, command.description]
|
365
|
-
end
|
366
|
-
log.puts
|
367
|
-
end
|
368
|
-
end
|
369
45
|
|
46
|
+
@commands = SymbolHash[
|
47
|
+
help: Help,
|
48
|
+
list: List,
|
49
|
+
add: Add,
|
50
|
+
url: URL,
|
51
|
+
search: Search,
|
52
|
+
]
|
370
53
|
|
371
54
|
# Singleton Methods
|
372
55
|
# ==========================================================================
|
373
56
|
|
374
57
|
def self.commands
|
375
|
-
|
376
|
-
help: Help,
|
377
|
-
list: List,
|
378
|
-
add: Add,
|
379
|
-
url: URL,
|
380
|
-
search: Search,
|
381
|
-
}
|
58
|
+
@commands
|
382
59
|
end
|
383
60
|
|
384
61
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class Add < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
DESCRIPTION = "Download version source and build object map"
|
37
|
+
USAGE = "yard stdlib add [OPTIONS] RUBY_VERSION"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
# Want to see what's going on by default here...
|
41
|
+
log.level = Logger::INFO
|
42
|
+
|
43
|
+
opts[ :force ] = false
|
44
|
+
|
45
|
+
OptionParser.new { |op|
|
46
|
+
add_header op
|
47
|
+
|
48
|
+
op.on( '-f', '--force',
|
49
|
+
%(Force building of map data when already present)
|
50
|
+
) { |force| opts[ :force ] = force }
|
51
|
+
|
52
|
+
}.parse! args
|
53
|
+
|
54
|
+
args.each do |version|
|
55
|
+
log.info "Adding object map for Ruby #{ version }..."
|
56
|
+
YARD::LinkStdlib::ObjectMap.add version, force: opts[ :force ]
|
57
|
+
end
|
58
|
+
|
59
|
+
exit true
|
60
|
+
end
|
61
|
+
|
62
|
+
end # class Add
|
63
|
+
|
64
|
+
|
65
|
+
# /Namespace
|
66
|
+
# =======================================================================
|
67
|
+
|
68
|
+
end # class LinkStdlib
|
69
|
+
end # module CLI
|
70
|
+
end # module YARD
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Deps ###
|
8
|
+
|
9
|
+
# We need {YARD::CLI::Command}
|
10
|
+
require 'yard'
|
11
|
+
|
12
|
+
### Project / Package ###
|
13
|
+
|
14
|
+
# `.make_missing`, `.set` from {YARD::LinkStdlib::RubySource}
|
15
|
+
require 'yard/link_stdlib/ruby_source'
|
16
|
+
|
17
|
+
|
18
|
+
# Namespace
|
19
|
+
# =======================================================================
|
20
|
+
|
21
|
+
module YARD
|
22
|
+
module CLI
|
23
|
+
class LinkStdlib < Command
|
24
|
+
|
25
|
+
|
26
|
+
# Definitions
|
27
|
+
# =======================================================================
|
28
|
+
|
29
|
+
module CommandHelper
|
30
|
+
|
31
|
+
def description
|
32
|
+
self.class::DESCRIPTION
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def usage
|
37
|
+
self.class::USAGE
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def check_args! args, count
|
42
|
+
if args.length < count
|
43
|
+
log.error "Too few args! Expected #{ count }, given #{ args.length }"
|
44
|
+
exit false
|
45
|
+
elsif args.length > count
|
46
|
+
log.error "Too many args! Expected #{ count }, given #{ args.length }"
|
47
|
+
exit false
|
48
|
+
end
|
49
|
+
|
50
|
+
if args.length == 1 then args[ 0 ] else args end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def opts
|
55
|
+
@opts ||= {}
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def add_header op, text = nil
|
60
|
+
op.banner = description
|
61
|
+
op.separator ''
|
62
|
+
op.separator 'Usage:'
|
63
|
+
op.separator ''
|
64
|
+
op.separator " #{ usage }"
|
65
|
+
op.separator ''
|
66
|
+
unless text.nil?
|
67
|
+
text.lines.each { |line| op.separator line }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Call {YARD::CLI::Command#common_options}, which adds file loading, plugin
|
71
|
+
# loading, logging, YARD version and help options
|
72
|
+
common_options( op )
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_version_opt op
|
76
|
+
# **DON'T** make missing versions by default here!
|
77
|
+
YARD::LinkStdlib::RubySource.make_missing = false
|
78
|
+
|
79
|
+
op.on(
|
80
|
+
'-R VERSION',
|
81
|
+
'--ruby-version=VERSION',
|
82
|
+
%(Set Ruby version)
|
83
|
+
) { |ruby_version|
|
84
|
+
YARD::LinkStdlib::RubyVersion.set ruby_version
|
85
|
+
}
|
86
|
+
|
87
|
+
op.on(
|
88
|
+
'--make-missing',
|
89
|
+
%(Download and make an object map if the Ruby version is not present)
|
90
|
+
) { |make_missing|
|
91
|
+
YARD::LinkStdlib::RubySource.make_missing = make_missing
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
end # CommandHelper
|
96
|
+
|
97
|
+
|
98
|
+
# /Namespace
|
99
|
+
# =======================================================================
|
100
|
+
|
101
|
+
end # class LinkStdlib
|
102
|
+
end # module CLI
|
103
|
+
end # module YARD
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class Help < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
USAGE = "yard stdlib help [OTHER_OPTIONS]"
|
37
|
+
DESCRIPTION = "Show this message"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
OptionParser.new { |op|
|
41
|
+
add_header op
|
42
|
+
}.parse! args
|
43
|
+
|
44
|
+
commands = LinkStdlib.commands
|
45
|
+
log.puts <<~END
|
46
|
+
yard-link_stdlib provides linking to online Ruby docs for standard
|
47
|
+
library code objects.
|
48
|
+
|
49
|
+
Usage:
|
50
|
+
|
51
|
+
yard stdlib COMMAND... [OPTIONS] [ARGS]
|
52
|
+
|
53
|
+
Commands:
|
54
|
+
|
55
|
+
END
|
56
|
+
commands.keys.sort_by(&:to_s).each do |command_name|
|
57
|
+
command_class = commands[command_name]
|
58
|
+
next unless command_class < Command
|
59
|
+
command = command_class.new
|
60
|
+
log.puts "%-8s %s" % [command_name, command.description]
|
61
|
+
end
|
62
|
+
log.puts
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# /Namespace
|
68
|
+
# =======================================================================
|
69
|
+
|
70
|
+
end # class LinkStdlib
|
71
|
+
end # module CLI
|
72
|
+
end # module YARD
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class List < Command
|
33
|
+
include CommandHelper
|
34
|
+
|
35
|
+
DESCRIPTION = "List Ruby versions"
|
36
|
+
USAGE = "yard stdlib list"
|
37
|
+
|
38
|
+
def run *args
|
39
|
+
OptionParser.new { |op|
|
40
|
+
add_header op
|
41
|
+
}.parse! args
|
42
|
+
|
43
|
+
check_args! args, 0
|
44
|
+
|
45
|
+
log.puts \
|
46
|
+
YARD::LinkStdlib::ObjectMap.
|
47
|
+
all.
|
48
|
+
map { |om| om.version.to_s }.
|
49
|
+
join( "\n" )
|
50
|
+
end
|
51
|
+
end # class List
|
52
|
+
|
53
|
+
|
54
|
+
# /Namespace
|
55
|
+
# =======================================================================
|
56
|
+
|
57
|
+
end # class LinkStdlib
|
58
|
+
end # module CLI
|
59
|
+
end # module YARD
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
# Hooks into {YARD::LinkStdlib::ObjectMap#grep} to search for names using
|
33
|
+
# regular expressions.
|
34
|
+
#
|
35
|
+
class Search < Command
|
36
|
+
|
37
|
+
include CommandHelper
|
38
|
+
|
39
|
+
DESCRIPTION = "Find stdlib names that match Regexp patterns"
|
40
|
+
USAGE = "yard stdlib search [OPTIONS] TERMS..."
|
41
|
+
|
42
|
+
def run *args
|
43
|
+
# Default format is `:plain`
|
44
|
+
opts[ :format ] = :plain
|
45
|
+
|
46
|
+
OptionParser.new { |op|
|
47
|
+
add_header op, <<~END
|
48
|
+
Examples:
|
49
|
+
|
50
|
+
1. {Pathname} instance methods
|
51
|
+
|
52
|
+
$ yard stdlib search '^Pathname#'
|
53
|
+
|
54
|
+
2. All `#to_s` methods
|
55
|
+
|
56
|
+
$ yard stdlib search '#to_s$'
|
57
|
+
|
58
|
+
3. Print results in serialized formats.
|
59
|
+
|
60
|
+
All `#to_s` instance methods in JSON:
|
61
|
+
|
62
|
+
$ yard stdlib search --format=json '#to_s$'
|
63
|
+
|
64
|
+
Supports a short `-f` flag and first-letter formats too.
|
65
|
+
|
66
|
+
Instance methods of {Array} in YAML:
|
67
|
+
|
68
|
+
$ yard stdlib search -f y '^Array#'
|
69
|
+
END
|
70
|
+
|
71
|
+
add_version_opt op
|
72
|
+
|
73
|
+
op.on( '-u', '--urls',
|
74
|
+
%(Print doc URLs along with names)
|
75
|
+
) { |urls| opts[ :urls ] = !!urls }
|
76
|
+
|
77
|
+
op.on( '-f FORMAT', '--format=FORMAT',
|
78
|
+
%(Specify print format: (p)lain, (j)son or (y)aml)
|
79
|
+
) { |format|
|
80
|
+
opts[ :format ] = \
|
81
|
+
case format.downcase
|
82
|
+
when 'p', 'plain'
|
83
|
+
:plain
|
84
|
+
when 'j', 'json'
|
85
|
+
:json
|
86
|
+
when 'y', 'yaml'
|
87
|
+
:yaml
|
88
|
+
else
|
89
|
+
log.fatal \
|
90
|
+
%(Unknown format - expected "plain", "json" or "yaml"; ) +
|
91
|
+
%(given #{ format.inspect })
|
92
|
+
exit false
|
93
|
+
end
|
94
|
+
}
|
95
|
+
|
96
|
+
}.parse! args
|
97
|
+
|
98
|
+
if args.empty?
|
99
|
+
YARD::LinkStdlib::ObjectMap.
|
100
|
+
current.
|
101
|
+
names.
|
102
|
+
sort_by( &:downcase ).
|
103
|
+
each { |key| log.puts key }
|
104
|
+
exit true
|
105
|
+
end
|
106
|
+
|
107
|
+
terms = args.map { |arg|
|
108
|
+
begin
|
109
|
+
Regexp.new arg
|
110
|
+
rescue RegexpError => error
|
111
|
+
Regexp.new \
|
112
|
+
Regexp.escape( YARD::LinkStdlib.normalize_name( arg ) )
|
113
|
+
end
|
114
|
+
}
|
115
|
+
|
116
|
+
log.debug "Terms:\n " + terms.map( &:to_s ).join( "\n " )
|
117
|
+
|
118
|
+
names = YARD::LinkStdlib.grep *terms
|
119
|
+
|
120
|
+
results = \
|
121
|
+
if opts[ :urls ]
|
122
|
+
names.each_with_object( {} ) { |name, hash|
|
123
|
+
hash[ name ] = YARD::LinkStdlib::ObjectMap.current.url_for name
|
124
|
+
}
|
125
|
+
else
|
126
|
+
names
|
127
|
+
end
|
128
|
+
|
129
|
+
case opts[ :format ]
|
130
|
+
when :plain
|
131
|
+
results.each do |entry|
|
132
|
+
if entry.is_a? ::Array
|
133
|
+
log.puts "#{ entry[0] } <#{ entry[ 1 ]}>"
|
134
|
+
else
|
135
|
+
log.puts entry
|
136
|
+
end
|
137
|
+
end
|
138
|
+
when :json
|
139
|
+
require 'json'
|
140
|
+
log.puts JSON.pretty_generate( results )
|
141
|
+
when :yaml
|
142
|
+
require 'yaml'
|
143
|
+
log.puts YAML.dump( results )
|
144
|
+
end
|
145
|
+
|
146
|
+
exit true
|
147
|
+
end
|
148
|
+
end # class Search
|
149
|
+
|
150
|
+
|
151
|
+
# /Namespace
|
152
|
+
# =======================================================================
|
153
|
+
|
154
|
+
end # class LinkStdlib
|
155
|
+
end # module CLI
|
156
|
+
end # module YARD
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class URL < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
DESCRIPTION = "Print the online doc URL for a stdlib name"
|
37
|
+
USAGE = "yard stdlib url [OPTIONS] NAME"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
OptionParser.new { |op|
|
41
|
+
add_header op
|
42
|
+
add_version_opt op
|
43
|
+
}.parse! args
|
44
|
+
|
45
|
+
name = check_args! args, 1
|
46
|
+
|
47
|
+
url = YARD::LinkStdlib::ObjectMap.current.url_for name
|
48
|
+
|
49
|
+
if url.nil?
|
50
|
+
$stderr.puts "Name not found: #{ name.inspect }"
|
51
|
+
exit false
|
52
|
+
end
|
53
|
+
|
54
|
+
puts url
|
55
|
+
exit true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# /Namespace
|
61
|
+
# =======================================================================
|
62
|
+
|
63
|
+
end # class LinkStdlib
|
64
|
+
end # module CLI
|
65
|
+
end # module YARD
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-link_stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -167,6 +167,12 @@ files:
|
|
167
167
|
- bin/make_map.rb
|
168
168
|
- lib/yard-link_stdlib.rb
|
169
169
|
- lib/yard/cli/link_stdlib.rb
|
170
|
+
- lib/yard/cli/link_stdlib/add.rb
|
171
|
+
- lib/yard/cli/link_stdlib/command_helper.rb
|
172
|
+
- lib/yard/cli/link_stdlib/help.rb
|
173
|
+
- lib/yard/cli/link_stdlib/list.rb
|
174
|
+
- lib/yard/cli/link_stdlib/search.rb
|
175
|
+
- lib/yard/cli/link_stdlib/url.rb
|
170
176
|
- lib/yard/link_stdlib.rb
|
171
177
|
- lib/yard/link_stdlib/html_helper.rb
|
172
178
|
- lib/yard/link_stdlib/object_map.rb
|