markdown_usage 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +123 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +214 -0
- data/Rakefile +10 -0
- data/bin/markdown_usage +71 -0
- data/lib/markdown_usage.rb +124 -0
- data/lib/markdown_usage/version.rb +3 -0
- data/markdown_usage.gemspec +30 -0
- data/usage.png +0 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47329a55cb6e0478a1b8cc63b31af8277c0b4044
|
4
|
+
data.tar.gz: 07666dcb0ca5534a2a13ec9141f01d0677c9e1ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72fd086d5627c74a96d3e1a268ee636f9ae59c5870f1832932e2f1805093a3ab2f1f85cff5b172988375921934a442a5dddacf248d5dca9e98311e8976fcadff
|
7
|
+
data.tar.gz: d309be6774f60eb387bf432ce38b1d6c3c7053aa7f5cbfb80a61399b4fc54301aec6f3171441e57823b34aa2662835c75978b1270554c94e7ad1006f0bc87e75
|
data/.gitignore
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/emacs,ruby
|
3
|
+
|
4
|
+
### Emacs ###
|
5
|
+
# -*- mode: gitignore; -*-
|
6
|
+
*~
|
7
|
+
\#*\#
|
8
|
+
/.emacs.desktop
|
9
|
+
/.emacs.desktop.lock
|
10
|
+
*.elc
|
11
|
+
auto-save-list
|
12
|
+
tramp
|
13
|
+
.\#*
|
14
|
+
|
15
|
+
# Org-mode
|
16
|
+
.org-id-locations
|
17
|
+
*_archive
|
18
|
+
|
19
|
+
# flymake-mode
|
20
|
+
*_flymake.*
|
21
|
+
|
22
|
+
# eshell files
|
23
|
+
/eshell/history
|
24
|
+
/eshell/lastdir
|
25
|
+
|
26
|
+
# elpa packages
|
27
|
+
/elpa/
|
28
|
+
|
29
|
+
# reftex files
|
30
|
+
*.rel
|
31
|
+
|
32
|
+
# AUCTeX auto folder
|
33
|
+
/auto/
|
34
|
+
|
35
|
+
# cask packages
|
36
|
+
.cask/
|
37
|
+
dist/
|
38
|
+
|
39
|
+
# Flycheck
|
40
|
+
flycheck_*.el
|
41
|
+
|
42
|
+
# server auth directory
|
43
|
+
/server/
|
44
|
+
|
45
|
+
# projectiles files
|
46
|
+
.projectile
|
47
|
+
projectile-bookmarks.eld
|
48
|
+
|
49
|
+
# directory configuration
|
50
|
+
.dir-locals.el
|
51
|
+
|
52
|
+
# saveplace
|
53
|
+
places
|
54
|
+
|
55
|
+
# url cache
|
56
|
+
url/cache/
|
57
|
+
|
58
|
+
# cedet
|
59
|
+
ede-projects.el
|
60
|
+
|
61
|
+
# smex
|
62
|
+
smex-items
|
63
|
+
|
64
|
+
# company-statistics
|
65
|
+
company-statistics-cache.el
|
66
|
+
|
67
|
+
# anaconda-mode
|
68
|
+
anaconda-mode/
|
69
|
+
|
70
|
+
### Ruby ###
|
71
|
+
*.gem
|
72
|
+
*.rbc
|
73
|
+
/.config
|
74
|
+
/coverage/
|
75
|
+
/InstalledFiles
|
76
|
+
/pkg/
|
77
|
+
/spec/reports/
|
78
|
+
/spec/examples.txt
|
79
|
+
/test/tmp/
|
80
|
+
/test/version_tmp/
|
81
|
+
/tmp/
|
82
|
+
|
83
|
+
# Used by dotenv library to load environment variables.
|
84
|
+
# .env
|
85
|
+
|
86
|
+
## Specific to RubyMotion:
|
87
|
+
.dat*
|
88
|
+
.repl_history
|
89
|
+
build/
|
90
|
+
*.bridgesupport
|
91
|
+
build-iPhoneOS/
|
92
|
+
build-iPhoneSimulator/
|
93
|
+
|
94
|
+
## Specific to RubyMotion (use of CocoaPods):
|
95
|
+
#
|
96
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
97
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
98
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
99
|
+
#
|
100
|
+
# vendor/Pods/
|
101
|
+
|
102
|
+
## Documentation cache and generated files:
|
103
|
+
/.yardoc/
|
104
|
+
/_yardoc/
|
105
|
+
/doc/
|
106
|
+
/rdoc/
|
107
|
+
|
108
|
+
## Environment normalization:
|
109
|
+
/.bundle/
|
110
|
+
/vendor/bundle
|
111
|
+
/lib/bundler/man/
|
112
|
+
|
113
|
+
# for a library or gem, you might want to ignore these files since the code is
|
114
|
+
# intended to run in multiple environments; otherwise, check them in:
|
115
|
+
Gemfile.lock
|
116
|
+
# .ruby-version
|
117
|
+
# .ruby-gemset
|
118
|
+
|
119
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
120
|
+
.rvmrc
|
121
|
+
|
122
|
+
|
123
|
+
# End of https://www.gitignore.io/api/emacs,ruby
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Skye Shaw
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
# MarkdownUsage
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/sshaw/markdown_usage.svg)](https://secure.travis-ci.org/sshaw/markdown_usage)
|
4
|
+
|
5
|
+
Output a colorized version of your program's usage using a Markdown document embedded in your script, from your project's README, or anywhere else.
|
6
|
+
|
7
|
+
`MarkdownUsage` uses [`TTY::Markdown`](https://github.com/piotrmurach/tty-markdown) to make
|
8
|
+
your program's usage look like this:
|
9
|
+
|
10
|
+
![MarkdownUsage output](usage.png)
|
11
|
+
|
12
|
+
If your program does not use Ruby or you want to minimize your dependencies use [the `markdown_usage` Script](#markdown_usage-command).
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
**Note: gem is not yet published**
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem "markdown_usage"
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install markdown_usage
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
When it's time to display your program's usage call `MarkdownUsage.print` or `MarkdownUsage()` with the [desired configuration options](#options).
|
35
|
+
By default it will look for the usage in [the invoking code's data section](http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-__END__),
|
36
|
+
output it to `stdout`, and call `exit 0`.
|
37
|
+
|
38
|
+
For more info see [Options](#options).
|
39
|
+
|
40
|
+
### Using `__END__`
|
41
|
+
|
42
|
+
Here's an example script:
|
43
|
+
|
44
|
+
```rb
|
45
|
+
#!/usr/bin/ruby
|
46
|
+
|
47
|
+
require "optparse"
|
48
|
+
require "markdown_usage"
|
49
|
+
|
50
|
+
OptionParser.new do |opts|
|
51
|
+
opts.on "-h", "--help" do
|
52
|
+
MarkdownUsage.print
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on "-o", "--do-something", "My great option" do |opt|
|
56
|
+
# ...
|
57
|
+
end
|
58
|
+
end.parse!
|
59
|
+
|
60
|
+
# The rest of your amazing program
|
61
|
+
|
62
|
+
__END__
|
63
|
+
**my_command** - command to do somethangz
|
64
|
+
|
65
|
+
## Usage
|
66
|
+
|
67
|
+
`my_command [options] file`
|
68
|
+
|
69
|
+
* `-a` This does foo
|
70
|
+
* `-b``MAP` Mapping for something
|
71
|
+
|
72
|
+
## MAP
|
73
|
+
|
74
|
+
Map is a list of blah pairs
|
75
|
+
|
76
|
+
## More Info
|
77
|
+
|
78
|
+
- [Docs](http://example.com/docs)
|
79
|
+
- [Bugs](http://example.com/bugs)
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
If you're using this and releasing your script as a gem it must be installed via `gem install --no-wrappers my_gem`
|
85
|
+
Otherwise, the data section will not be available to due the wrapper script added by RubyGems.
|
86
|
+
|
87
|
+
In this case it's better to use a file for the usage
|
88
|
+
|
89
|
+
### Using a File
|
90
|
+
|
91
|
+
To extract the program's usage from the `Usage` section of your project's README:
|
92
|
+
|
93
|
+
```rb
|
94
|
+
MarkdownUsage.print(:source => "README", :sections => "Usage")
|
95
|
+
```
|
96
|
+
|
97
|
+
This will look for a file name `README.md` or `README.markdown` in your project's root directory.
|
98
|
+
|
99
|
+
Multiple sections can be extracted:
|
100
|
+
|
101
|
+
```rb
|
102
|
+
MarkdownUsage.print(:source => "README", :sections => %w[Usage Support])
|
103
|
+
```
|
104
|
+
|
105
|
+
To use a different file specify its path:
|
106
|
+
|
107
|
+
```rb
|
108
|
+
MarkdownUsage.print(:source => "path/to/README.md")
|
109
|
+
```
|
110
|
+
|
111
|
+
When specifying a path you must provide the appropriate extension.
|
112
|
+
|
113
|
+
### Options
|
114
|
+
|
115
|
+
`MarkdownUsage.print` and `MarkdownUsage()` accept a `Hash` of the following options:
|
116
|
+
|
117
|
+
#### `:exit`
|
118
|
+
|
119
|
+
Exit status to use after printing usage, defaults to `0`.
|
120
|
+
|
121
|
+
Set this to `false` to prevent `exit` from being called.
|
122
|
+
|
123
|
+
#### `:output`
|
124
|
+
|
125
|
+
File handle to output the usage on. Defaults to `$stdout`. The given handle must
|
126
|
+
have a `#puts` method.
|
127
|
+
|
128
|
+
The usage will *always* contain terminal escape codes.
|
129
|
+
|
130
|
+
#### `:sections`
|
131
|
+
|
132
|
+
Sections to extract from the `:source`. These must be the headings without the
|
133
|
+
leading or trailing heading format characters.
|
134
|
+
|
135
|
+
If the heading text has other formatting characters, they must be included (see [Examples](#examples)).
|
136
|
+
|
137
|
+
Can be a `String` or an `Array` of strings.
|
138
|
+
|
139
|
+
#### `:source`
|
140
|
+
|
141
|
+
Location of usage Markdown to print, defaults to your program's data (`__END__`) section.
|
142
|
+
|
143
|
+
To load a Markdown `README` from your project's root directory set this to `README`.
|
144
|
+
|
145
|
+
Relative paths will be loaded relative to your project's root directory.
|
146
|
+
|
147
|
+
#### `:raise_errors`
|
148
|
+
|
149
|
+
If `true` a `MarkdownUsage::Error` will be raised when `MarkdownUsage` encounters a problem.
|
150
|
+
If `false` a warning is sent to `stderr` instead.
|
151
|
+
|
152
|
+
## `markdown_usage` Command
|
153
|
+
|
154
|
+
Embed or output a colorized version of your program's usage from a Markdown document.
|
155
|
+
|
156
|
+
### Usage
|
157
|
+
|
158
|
+
```
|
159
|
+
markdown_usage [-hv] [-s sections] [-o output] markdown_doc
|
160
|
+
```
|
161
|
+
|
162
|
+
`markdown_doc` is a file containing the Markdown to use.
|
163
|
+
|
164
|
+
- `-h` show this help menu
|
165
|
+
- `-o` `output` where to output the colorized usage, defaults to `stdout`
|
166
|
+
- `-s` `sections` sections to extract from `markdown_doc`
|
167
|
+
- `-v` show the version
|
168
|
+
|
169
|
+
#### `output`
|
170
|
+
|
171
|
+
This can be a file or a script. If it's a script it will be added to the script's data section.
|
172
|
+
Existing data section content will be overwritten.
|
173
|
+
|
174
|
+
We assume `output` is a script if one of the following are true:
|
175
|
+
|
176
|
+
- It ends in `.rb` or `.pl` (these languages support data sections)
|
177
|
+
- It contains *nix shebang on the first line for `ruby` or `perl` e.g., `#!/usr/bin/env ruby`
|
178
|
+
|
179
|
+
#### `sections`
|
180
|
+
|
181
|
+
These must be the headings without leading or trailing heading format characters.
|
182
|
+
If the heading text has other formatting characters, they must be included (see [Examples](#examples)).
|
183
|
+
|
184
|
+
Multiple sections can be separated by a comma.
|
185
|
+
|
186
|
+
### Examples
|
187
|
+
|
188
|
+
Output the section `Usage` from `README.md` to `USAGE`:
|
189
|
+
|
190
|
+
```
|
191
|
+
markdown_usage -s Usage README.md > USAGE
|
192
|
+
```
|
193
|
+
|
194
|
+
Output the sections `Usage` and `More Info` from `README.md` to `USAGE`:
|
195
|
+
|
196
|
+
```
|
197
|
+
markdown_usage -s 'Usage,More Info' README.md > USAGE
|
198
|
+
```
|
199
|
+
|
200
|
+
Add the following formatted section to the data section of `script.rb`:
|
201
|
+
|
202
|
+
```
|
203
|
+
markdown_usage -s '`markdown_usage` Command' -o script.rb README.md
|
204
|
+
```
|
205
|
+
|
206
|
+
## See Also
|
207
|
+
|
208
|
+
- [`TTY::Markdown`](https://github.com/piotrmurach/tty-markdown) - without this there would be no `MarkdownUsage`
|
209
|
+
- [tty_markdown](http://github.com/dapplebeforedawn/tty_markdown)
|
210
|
+
- Perl's [`Pod::Usage`](https://metacpan.org/pod/Pod::Usage) - the inspiration for `MarkdownUsage`
|
211
|
+
|
212
|
+
## License
|
213
|
+
|
214
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
Rake::TestTask.new
|
6
|
+
|
7
|
+
desc "Embed the usage doc from README.md in bin/markdown_usage"
|
8
|
+
task :embed_usage do
|
9
|
+
sh "bin/markdown_usage -o bin/markdown_usage -s '`markdown_usage` Script' README.md"
|
10
|
+
end
|
data/bin/markdown_usage
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "stringio"
|
4
|
+
require "tempfile"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
require "markdown_usage"
|
8
|
+
|
9
|
+
def script?(path)
|
10
|
+
# Other langs that support DATA sections?
|
11
|
+
%w[.rb .pl].include?(File.extname(path)) ||
|
12
|
+
File.file?(path) && File.open(path) { |io| return io.gets =~ /\A#!.*\b(?:perl|ruby)/ }
|
13
|
+
end
|
14
|
+
|
15
|
+
def usage(status = 1)
|
16
|
+
MarkdownUsage(:source => "README", :sections => "`markdown_usage` Command")
|
17
|
+
end
|
18
|
+
|
19
|
+
options = { :exit => false }
|
20
|
+
|
21
|
+
while ARGV.any?
|
22
|
+
case ARGV[0]
|
23
|
+
when "-h", "--help"
|
24
|
+
usage(0)
|
25
|
+
when "-o"
|
26
|
+
ARGV.shift
|
27
|
+
usage unless ARGV[0]
|
28
|
+
output = ARGV.shift
|
29
|
+
when "-s"
|
30
|
+
ARGV.shift
|
31
|
+
usage unless ARGV[0]
|
32
|
+
options[:sections] = ARGV.shift.split(",")
|
33
|
+
when "-v", "--version"
|
34
|
+
puts "v#{MarkdownUsage::VERSION}"
|
35
|
+
exit
|
36
|
+
else
|
37
|
+
options[:source] = ARGV.shift
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
usage unless options[:source]
|
42
|
+
|
43
|
+
unless output
|
44
|
+
MarkdownUsage(options.merge(:output => $stdout))
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
unless script?(output)
|
49
|
+
File.open(output, "w+") { |io| MarkdownUsage.print(options.merge(:output => io)) }
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
io = StringIO.new
|
54
|
+
MarkdownUsage(options.merge(:output => io))
|
55
|
+
io.rewind
|
56
|
+
|
57
|
+
data = File.read(output)
|
58
|
+
code = data.split(/^__END__$/, 2)
|
59
|
+
code[1] = io.string
|
60
|
+
|
61
|
+
out = Tempfile.new("MarkdownUsage")
|
62
|
+
out.puts code[0]
|
63
|
+
out.puts "__END__"
|
64
|
+
out << code[1]
|
65
|
+
out.close
|
66
|
+
|
67
|
+
# Will this reset permissions on Windows?
|
68
|
+
FileUtils.chmod(File.stat(output).mode, out.path)
|
69
|
+
FileUtils.mv(out.path, output)
|
70
|
+
|
71
|
+
out.unlink
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require "tty/markdown"
|
2
|
+
require "markdown_usage/version"
|
3
|
+
|
4
|
+
module MarkdownUsage
|
5
|
+
Error = Class.new(StandardError)
|
6
|
+
|
7
|
+
HEADING = /\A(\#{1,6})/
|
8
|
+
ALT_HEADING = /\A([-=]+)\s*\Z/
|
9
|
+
ALT_HEADING_LEVELS = { "=" => 1, "-" => 2 }.freeze
|
10
|
+
|
11
|
+
STACKTRACE = /\A(.+):\d+:in\s+`(.+)'/
|
12
|
+
|
13
|
+
EXTENSIONS = %w[md markdown].freeze
|
14
|
+
|
15
|
+
class << self
|
16
|
+
#
|
17
|
+
# Print the calling program's usage based on +options+.
|
18
|
+
# See README for a list of +options+.
|
19
|
+
#
|
20
|
+
def print(options = nil)
|
21
|
+
options ||= {}
|
22
|
+
|
23
|
+
output = options[:output] || $stdout
|
24
|
+
exitcode = options.include?(:exit) ? options[:exit] : 0
|
25
|
+
raise_errors = options.include?(:raise_errors) ? options[:raise_errors] : true
|
26
|
+
|
27
|
+
error("Usage document cannot be found", raise_errors) and return unless defined?(DATA) || options[:source]
|
28
|
+
|
29
|
+
if !options[:source]
|
30
|
+
lines = DATA.readlines
|
31
|
+
else
|
32
|
+
|
33
|
+
source = find_readme(options[:source], find_root_directory)
|
34
|
+
error("Cannot find usage source: #{options[:source]}", raise_errors) and return unless source
|
35
|
+
|
36
|
+
lines = File.readlines(source)
|
37
|
+
end
|
38
|
+
|
39
|
+
output.puts TTY::Markdown.parse(extract_usage(lines, options[:sections]))
|
40
|
+
exit exitcode unless exitcode == false
|
41
|
+
rescue => e
|
42
|
+
error(e, raise_errors)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def find_root_directory
|
48
|
+
# caller[0] = MarkdownUsage.print
|
49
|
+
# caller[1] = May be caller or MarkdownUsage(), skip the latter
|
50
|
+
# caller[2] = May be caller
|
51
|
+
root = "."
|
52
|
+
return root unless caller[1] =~ STACKTRACE
|
53
|
+
|
54
|
+
root = File.dirname($1)
|
55
|
+
return root if $2 != "MarkdownUsage"
|
56
|
+
|
57
|
+
root = File.dirname($1) if caller[2] =~ STACKTRACE
|
58
|
+
root
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_readme(source, caller_root)
|
62
|
+
return source if File.exists?(source)
|
63
|
+
|
64
|
+
roots = [ caller_root ]
|
65
|
+
roots << File.dirname(roots[0]) if %w[bin exe].include?(File.basename(roots[0]))
|
66
|
+
|
67
|
+
if source != "README"
|
68
|
+
roots.map { |dir| File.join(dir, source) }.find { |path| File.exists?(path) }
|
69
|
+
else
|
70
|
+
roots.each do |dir|
|
71
|
+
readme = EXTENSIONS.map { |ext| File.join(dir, "README.#{ext}") }.find { |path| File.exists?(path) }
|
72
|
+
return readme if readme
|
73
|
+
end
|
74
|
+
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def error(message, raise_errors = false)
|
80
|
+
raise Error, message if raise_errors
|
81
|
+
warn "MarkdownUsage warning: #{message}"
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def extract_usage(lines, sections)
|
86
|
+
sections = Array(sections).map { |text| Regexp.quote(text) }
|
87
|
+
return lines.join("") unless sections.any?
|
88
|
+
|
89
|
+
usage = ""
|
90
|
+
while lines.any?
|
91
|
+
sections.each do |pat|
|
92
|
+
next unless lines[0] =~ /#{HEADING}\s*#{pat}/ || lines[0] =~ /\A#{pat}/ && lines[1] =~ ALT_HEADING
|
93
|
+
|
94
|
+
# TTY::Markdown (Kramdown) chooses the last char to denote heading level
|
95
|
+
cur_level = lines[0][0] == "#" ? $1.size : ALT_HEADING_LEVELS[$1[-1]]
|
96
|
+
|
97
|
+
usage << lines.shift
|
98
|
+
|
99
|
+
while lines.any?
|
100
|
+
next_level = if lines[0] =~ /#{HEADING}\s*\S/
|
101
|
+
$1.size
|
102
|
+
elsif lines[0] =~ /./ && lines[1] =~ ALT_HEADING
|
103
|
+
ALT_HEADING_LEVELS[$1[-1]]
|
104
|
+
end
|
105
|
+
|
106
|
+
break if next_level && next_level <= cur_level
|
107
|
+
usage << lines.shift
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
lines.shift
|
112
|
+
end
|
113
|
+
|
114
|
+
usage
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Calls MarkdownUsage.print. See README for +options+.
|
121
|
+
#
|
122
|
+
def MarkdownUsage(options = nil)
|
123
|
+
MarkdownUsage.print(options)
|
124
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "markdown_usage/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "markdown_usage"
|
7
|
+
spec.version = MarkdownUsage::VERSION
|
8
|
+
spec.authors = ["Skye Shaw"]
|
9
|
+
spec.email = ["skye.shaw@gmail.com"]
|
10
|
+
spec.summary =<<-DESC
|
11
|
+
Output a colorized version of your program's usage using a Markdown document embedded in your script,
|
12
|
+
from your project's README, or anywhere else.
|
13
|
+
DESC
|
14
|
+
spec.homepage = "https://github.com/sshaw/markdown_usage"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "tty-markdown", "~> 0.2"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
26
|
+
spec.add_development_dependency "climate_control", "~> 0.1"
|
27
|
+
spec.add_development_dependency "io-grab", "~> 0.0.2"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
end
|
data/usage.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markdown_usage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Skye Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tty-markdown
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: climate_control
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: io-grab
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- skye.shaw@gmail.com
|
100
|
+
executables:
|
101
|
+
- markdown_usage
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/markdown_usage
|
113
|
+
- lib/markdown_usage.rb
|
114
|
+
- lib/markdown_usage/version.rb
|
115
|
+
- markdown_usage.gemspec
|
116
|
+
- usage.png
|
117
|
+
homepage: https://github.com/sshaw/markdown_usage
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.6.14
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Output a colorized version of your program's usage using a Markdown document
|
141
|
+
embedded in your script, from your project's README, or anywhere else.
|
142
|
+
test_files: []
|