binman 3.2.1 → 3.3.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59dacb035f95229d4261bc1ede0d49c5351d2bfd
4
+ data.tar.gz: 3d08a026878970843143de1234a6f9274b94c166
5
+ SHA512:
6
+ metadata.gz: b4687dde4ceb788cdb51a298d0e10a4798904467d7aac99531401f327e7e4c02d7c873503f81a63ee8310b5fc80f7a2cd95b901b6f06e762fcd1e47926a23089
7
+ data.tar.gz: aa1b36901f76a242909f99595eaee06f4b63897cf6197c9b6b8e9d9d6b7b3b6d7780cfe671f7e81b380004a248486ef15661545368df46b3e051b868ef8fbae0
data/README.markdown CHANGED
@@ -47,6 +47,8 @@ If you also want to build your own manual pages:
47
47
 
48
48
  ### At the command line
49
49
 
50
+ See binman(1) manual:
51
+
50
52
  binman --help
51
53
 
52
54
  ### Inside a Ruby script
@@ -210,12 +212,21 @@ You can also write the manual as a multi-line Ruby comment inside an `if 0`:
210
212
 
211
213
  ## Packaging
212
214
 
213
- ### Pre-building man pages
215
+ ### Building man pages
216
+
217
+ #### At the command line
218
+
219
+ See binman-rake(1) manual:
220
+
221
+ binman-rake --help
222
+
223
+ #### Inside a Ruby script
214
224
 
215
- Add the following lines to your gemspec:
225
+ Add this snippet to your gemspec file:
216
226
 
217
- s.files += Dir['man/man?/*.?']
218
- s.add_development_dependency 'md2man', '~> 1.4'
227
+ s.files += Dir['man/man?/*.?'] # UNIX man pages
228
+ s.files += Dir['man/**/*.{html,css,js}'] # HTML man pages
229
+ s.add_development_dependency 'md2man', '~> 2.0'
219
230
 
220
231
  Add the following line to your Rakefile:
221
232
 
@@ -1,3 +1,19 @@
1
+ ## Version 3.3.0 (2013-05-08)
2
+
3
+ Minor:
4
+
5
+ * Add binman-rake(1) script to provide access to `binman/rakefile` tasks.
6
+
7
+ * Always try showing HTML manual page in web browser from `BinMan.show()`.
8
+
9
+ Other:
10
+
11
+ * Upgrade to md2man 2.0.0.
12
+
13
+ * Rename HISTORY to VERSION so it sorts after README.
14
+
15
+ * Add man/man0/ subdir containing README and VERSION.
16
+
1
17
  ## Version 3.2.1 (2013-05-04)
2
18
 
3
19
  Patch:
data/bin/binman CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  =begin =======================================================================
3
3
 
4
- # BINMAN 1 2013-05-04 3.2.1
4
+ # BINMAN 1 2013-05-08 3.3.0
5
5
 
6
6
  ## NAME
7
7
 
@@ -55,8 +55,8 @@ The following [Redcarpet] extensions are enabled while processing markdown(7):
55
55
  * autolink
56
56
  * superscript
57
57
  * strikethrough
58
- * no_intra_emphasis
59
- * fenced_code_blocks
58
+ * no\_intra\_emphasis
59
+ * fenced\_code\_blocks
60
60
 
61
61
  ## OPTIONS
62
62
 
data/bin/binman-rake ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ =begin =======================================================================
3
+
4
+ # BINMAN-RAKE 1 2013-05-08 3.3.0
5
+
6
+ ## NAME
7
+
8
+ binman-rake - run rake(1) tasks from binman(1)
9
+
10
+ ## SYNOPSIS
11
+
12
+ `binman-rake` [*OPTION*]... [*TASK*]...
13
+
14
+ ## DESCRIPTION
15
+
16
+ This program lets you run rake(1) tasks provided by binman(1) without having
17
+ to create a special file named `Rakefile` that contains the following snippet:
18
+
19
+ require 'binman/rakefile'
20
+
21
+ If no *TASK* is specified, then the `binman` task is run by default.
22
+
23
+ ## TASKS
24
+
25
+ `binman`
26
+ Runs the `binman:man` and `binman:web` tasks, in that order.
27
+
28
+ `binman:man`
29
+ Builds UNIX manual pages from scripts found in your `bin/` directory.
30
+ It also runs the `md2man:man` task, provided by md2man-rake(1), which
31
+ builds UNIX manual pages from `*.markdown`, `*.mkd`, and `*.md` files
32
+ found in or beneath the `man/` subdirectory in your working directory.
33
+
34
+ `binman:web`
35
+ Builds HTML manual pages from scripts found in your `bin/` directory.
36
+ It also runs the `md2man:web` task, provided by md2man-rake(1), which
37
+ builds HTML manual pages from `*.markdown`, `*.mkd`, and `*.md` files
38
+ found in or beneath the `man/` subdirectory in your working directory.
39
+
40
+ ## OPTIONS
41
+
42
+ `-h`, `--help`
43
+ Show this help manual.
44
+
45
+ Run `rake --help` to see more options.
46
+
47
+ ## SEE ALSO
48
+
49
+ rake(1), binman(1), md2man-rake(1)
50
+
51
+ =end =========================================================================
52
+
53
+ require 'binman'
54
+ BinMan.help
55
+
56
+ require 'rake'
57
+ Rake.application.init File.basename(__FILE__)
58
+
59
+ require 'binman/rakefile'
60
+ task :default => :binman
61
+
62
+ Rake.application.top_level
data/binman.gemspec CHANGED
@@ -16,6 +16,10 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_development_dependency 'md2man', '~> 1.4'
19
+ s.files += Dir['man/man?/*.?'] # UNIX man pages
20
+ s.files += Dir['man/**/*.{html,css,js}'] # HTML man pages
21
+ s.add_development_dependency 'md2man', '~> 2.0'
22
+
23
+ s.add_dependency 'opener', '>= 0.1.0', '< 1'
20
24
  s.add_development_dependency 'rake', '>= 0.9.2.2', '< 1'
21
25
  end
data/lib/binman.rb CHANGED
@@ -31,10 +31,10 @@ module BinMan
31
31
 
32
32
  # Converts given markdown(7) source into roff(7).
33
33
  def conv source=nil
34
- require 'md2man'
35
- Md2Man::ENGINE.render(read(source))
34
+ require 'md2man/roff/engine'
35
+ Md2Man::Roff::ENGINE.render(read(source))
36
36
  rescue LoadError
37
- raise 'Run `gem install md2man -v "~>1"` to use BinMan::conv().'
37
+ raise 'Run `gem install md2man --version "~> 2.0"` to use BinMan::conv().'
38
38
  end
39
39
 
40
40
  # Extracts leading comment header content from given
@@ -47,10 +47,23 @@ module BinMan
47
47
  # possible, else falls back to showing leading comment header as-is.
48
48
  def show source=nil
49
49
  # try showing existing man page files for given source
50
- return if file = find(source) and File.exist? file and
51
- File.exist? man_path = File.expand_path('../../man', file) and
52
- system 'man', '-M', man_path, '-a', File.basename(file)
50
+ if file = find(source) and File.exist? file
51
+ man_page = File.basename(file)
52
+ man_path = File.expand_path('../../man', file)
53
53
 
54
+ # try showing HTML manual page in a web browser in background
55
+ require 'opener'
56
+ Dir["#{man_path}/**/#{man_page}.*.html"].each do |man_html|
57
+ # close streams to avoid interference with man(1) reader below
58
+ Opener.spawn man_html, 0 => :close, 1 => :close, 2 => :close
59
+ end
60
+
61
+ # try showing roff manual page in man(1) reader in foreground;
62
+ # close STDERR to avoid interference with the fall back below
63
+ return if system 'man', '-M', man_path, '-a', man_page, 2 => :close
64
+ end
65
+
66
+ # fall back to showing leading comment header as-is
54
67
  header = load(source)
55
68
 
56
69
  begin
@@ -26,7 +26,6 @@ end
26
26
  desc 'Build UNIX manual pages for bin/ scripts.'
27
27
  task 'binman:man' => mkds do
28
28
  #-----------------------------------------------------------------------------
29
- require 'md2man'
30
29
  load 'md2man/rakefile.rb'
31
30
  Rake::Task['md2man:man'].invoke
32
31
  end
@@ -35,7 +34,6 @@ end
35
34
  desc 'Build HTML manual pages for bin/ scripts.'
36
35
  task 'binman:web' => mkds do
37
36
  #-----------------------------------------------------------------------------
38
- require 'md2man'
39
37
  load 'md2man/rakefile.rb'
40
38
  Rake::Task['md2man:web'].invoke
41
39
  end
@@ -1,3 +1,3 @@
1
1
  module BinMan
2
- VERSION = "3.2.1"
2
+ VERSION = "3.3.0"
3
3
  end
data/man/index.html ADDED
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="generator" content="md2man 2.0.0 https://github.com/sunaku/md2man" />
6
+ <title>man/index</title>
7
+ <link rel="stylesheet" href="style.css"/>
8
+ <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
9
+ </head>
10
+ <body><div class="container-fluid"><h2 id="man0">man0</h2><dl class="dl-horizontal"><dt><a href="man0/README.html">README</a></dt><dd></dd></dl><dl class="dl-horizontal"><dt><a href="man0/VERSION.html">VERSION</a></dt><dd></dd></dl><h2 id="man1">man1</h2><dl class="dl-horizontal"><dt><a href="man1/binman-rake.1.html">binman-rake(1)</a></dt><dd>run rake(1) tasks from binman(1)</dd></dl><dl class="dl-horizontal"><dt><a href="man1/binman.1.html">binman(1)</a></dt><dd>man pages for bin scripts</dd></dl></div></body>
11
+ </html>
@@ -0,0 +1,198 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="generator" content="md2man 2.0.0 https://github.com/sunaku/md2man" />
6
+ <title>README</title>
7
+ <link rel="stylesheet" href="../style.css"/>
8
+ <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
9
+ </head>
10
+ <body><div class="navbar"><div class="navbar-inner"><span class="brand"><a href="../index.html#man0">man0</a>/README</span></div></div><div class="container-fluid"><h1 id="binman-man-pages-for-bin-scripts">binman - man pages for bin scripts</h1><p><a href="https://github.com/sunaku/binman">binman</a> produces UNIX manual pages for executable scripts using <a href="https://github.com/sunaku/md2man">md2man</a>.</p><h2 id="Features">Features</h2>
11
+ <ul>
12
+ <li><p>Supports any scripting language that has multi-line
13
+ comments or uses <code>#</code> for single-line comments: Ruby,
14
+ Perl, Python, Node.js, Tcl, AWK, UNIX shell, and more!</p></li>
15
+ <li><p>Provides a Ruby library and a command-line client too.</p></li>
16
+ <li><p>Individual extraction, conversion, and display commands.</p></li>
17
+ <li><p>Implemented in roughly 100 lines of pure Ruby code! :-)</p></li>
18
+ </ul>
19
+ <h3 id="Demonstration">Demonstration</h3><p><img src="http://ompldr.org/vYm5mcg" alt="Obligatory screen-shot of binman(1) in action!"></p><p>Here is <a href="https://raw.github.com/sunaku/binman/master/bin/binman">a complete example in Ruby</a> to help you get started.
20
+ For examples in other scripting languages, see the &quot;Usage&quot; section below!</p><h2 id="Installation">Installation</h2><p>If you only want to view pre-built manual pages:</p>
21
+ <pre><code>gem install binman
22
+ </code></pre>
23
+ <p>If you also want to build your own manual pages:</p>
24
+ <pre><code>gem install md2man -v &#39;~&gt; 1.4&#39;
25
+ </code></pre>
26
+ <h3 id="Prerequisites">Prerequisites</h3>
27
+ <ul>
28
+ <li>Ruby 1.8.7 or 1.9.2 or newer.</li>
29
+ </ul>
30
+ <h3 id="Development">Development</h3>
31
+ <pre><code>git clone git://github.com/sunaku/binman
32
+ cd binman
33
+ bundle install
34
+ bundle exec binman --help # run it directly
35
+ bundle exec rake --tasks # packaging tasks
36
+ </code></pre>
37
+ <h2 id="Usage">Usage</h2><h3 id="At-the-command-line">At the command line</h3><p>See <a class="md2man-xref" href="../man1/binman.1.html">binman(1)</a> manual:</p>
38
+ <pre><code>binman --help
39
+ </code></pre>
40
+ <h3 id="Inside-a-Ruby-script">Inside a Ruby script</h3>
41
+ <pre><code>#!/usr/bin/env ruby
42
+ # your program&#39;s manual page goes here
43
+
44
+ require &#39;binman&#39;
45
+
46
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
47
+ BinMan.help
48
+
49
+ # OPTION 2: show manual unconditionally
50
+ BinMan.show
51
+ </code></pre>
52
+ <p>You can also specify your program&#39;s source file encoding above the manual:</p>
53
+ <pre><code>#!/usr/bin/env ruby
54
+ # -*- coding: utf-8 -*-
55
+ # your program&#39;s manual page goes here
56
+ </code></pre>
57
+ <p>You can also write the manual as a multi-line Ruby comment:</p>
58
+ <pre><code>#!/usr/bin/env ruby
59
+ =begin
60
+ your program&#39;s manual page goes here
61
+ =end
62
+ </code></pre>
63
+ <p>You can also specify your program&#39;s source file encoding above the manual:</p>
64
+ <pre><code>#!/usr/bin/env ruby
65
+ # -*- coding: utf-8 -*-
66
+ =begin
67
+ your program&#39;s manual page goes here
68
+ =end
69
+ </code></pre>
70
+ <p>See the <a href="http://rubydoc.info/gems/binman/frames">API documentation</a> for even more possibilities!</p><h3 id="Inside-a-shell-script">Inside a shell script</h3>
71
+ <pre><code>#!/usr/bin/sh
72
+ # your program&#39;s manual page goes here
73
+
74
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
75
+ binman help &quot;$0&quot; &quot;$@&quot; &amp;&amp; exit
76
+
77
+ # OPTION 2: show manual unconditionally
78
+ binman show &quot;$0&quot;
79
+ </code></pre>
80
+ <h3 id="Inside-a-Perl-script">Inside a Perl script</h3>
81
+ <pre><code>#!/usr/bin/env perl
82
+ # your program&#39;s manual page goes here
83
+
84
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
85
+ system(&#39;binman&#39;, &#39;help&#39;, __FILE__, @ARGV) == 0 and exit;
86
+
87
+ # OPTION 2: show manual unconditionally
88
+ system(&#39;binman&#39;, &#39;show&#39;, __FILE__);
89
+ </code></pre>
90
+ <p>You can also write the manual as a multi-line Ruby comment after <code>__END__</code>:</p>
91
+ <pre><code>#!/usr/bin/env perl
92
+ print &quot;your program&#39;s code goes here&quot;;
93
+ __END__
94
+ =begin
95
+ your program&#39;s manual page goes here
96
+ =end
97
+ </code></pre>
98
+ <h3 id="Inside-a-Python-script">Inside a Python script</h3>
99
+ <pre><code>#!/usr/bin/env python
100
+ # your program&#39;s manual page goes here
101
+
102
+ import sys, subprocess
103
+
104
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
105
+ subprocess.call([&#39;binman&#39;, &#39;help&#39;, __file__] + sys.argv) == 0 and sys.exit()
106
+
107
+ # OPTION 2: show manual unconditionally
108
+ subprocess.call([&#39;binman&#39;, &#39;show&#39;, __file__])
109
+ </code></pre>
110
+ <p>You can also specify your program&#39;s source file encoding above the manual:</p>
111
+ <pre><code>#!/usr/bin/env python
112
+ # -*- coding: utf-8 -*-
113
+ # your program&#39;s manual page goes here
114
+ </code></pre>
115
+ <p>You can also write the manual as a multi-line Ruby comment inside a docstring:</p>
116
+ <pre><code>#!/usr/bin/env python
117
+ &quot;&quot;&quot;
118
+ =begin
119
+ your program&#39;s manual page goes here
120
+ =end
121
+ &quot;&quot;&quot;
122
+ </code></pre>
123
+ <p>You can also specify your program&#39;s source file encoding above the manual:</p>
124
+ <pre><code>#!/usr/bin/env python
125
+ # -*- coding: utf-8 -*-
126
+ &quot;&quot;&quot;
127
+ =begin
128
+ your program&#39;s manual page goes here
129
+ =end
130
+ &quot;&quot;&quot;
131
+ </code></pre>
132
+ <h3 id="Inside-an-AWK-script">Inside an AWK script</h3><p>The technique for determining current AWK script file name <a href="http://www.mombu.com/programming/programming/t-the-name-of-script-itself-2040784-print.html">comes from here</a>.</p>
133
+ <pre><code>#!/usr/bin/awk -f
134
+ # your program&#39;s manual page goes here
135
+
136
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
137
+ BEGIN {getline c &lt;&quot;/proc/self/cmdline&quot;; sub(&quot;.*-f\0&quot;,&quot; &quot;,c); gsub(&quot;\0&quot;,&quot; &quot;,c);
138
+ if(system(&quot;binman help&quot; c) == 0){ exit }}
139
+
140
+ # OPTION 2: show manual unconditionally
141
+ BEGIN {getline c &lt;&quot;/proc/self/cmdline&quot;; sub(&quot;.*-f\0&quot;,&quot; &quot;,c); sub(&quot;\0.*&quot;,&quot;&quot;,c);
142
+ system(&quot;binman show&quot; c)}
143
+ </code></pre>
144
+ <h3 id="Inside-a-Tcl-script">Inside a Tcl script</h3>
145
+ <pre><code>#!/usr/bin/env tclsh
146
+ # your program&#39;s manual page goes here
147
+
148
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
149
+ if {![catch {exec -- &gt;/dev/tty binman help $argv0 {*}$argv}]} {exit}
150
+
151
+ # OPTION 2: show manual unconditionally
152
+ exec &gt;/dev/tty binman show $argv0
153
+ </code></pre>
154
+ <p>You can also write the manual as a multi-line Ruby comment inside an <code>if 0</code>:</p>
155
+ <pre><code>#!/usr/bin/env tclsh
156
+ if 0 {
157
+ =begin
158
+ your program&#39;s manual page goes here
159
+ =end
160
+ }
161
+ </code></pre>
162
+ <h3 id="Inside-a-Node-js-script">Inside a Node.js script</h3>
163
+ <pre><code>/*
164
+ =begin
165
+ your program&#39;s manual page goes here
166
+ =end
167
+ */
168
+
169
+ var exec = require(&#39;child_process&#39;).exec;
170
+
171
+ // OPTION 1: show manual and exit if ARGV has -h or --help except after --
172
+ exec([&#39;&gt;/dev/tty&#39;, &#39;binman&#39;, &#39;help&#39;, __filename].concat(process.argv).
173
+ join(&#39; &#39;), <a class="md2man-xref">function(error)</a>{ if (error === null){ process.exit(); } });
174
+
175
+ // OPTION 2: show manual unconditionally
176
+ exec([&#39;&gt;/dev/tty&#39;, &#39;binman&#39;, &#39;show&#39;, __filename].join(&#39; &#39;));
177
+ </code></pre>
178
+ <h2 id="Packaging">Packaging</h2><h3 id="Building-man-pages">Building man pages</h3><h4 id="At-the-command-line">At the command line</h4><p>See <a class="md2man-xref" href="../man1/binman-rake.1.html">binman-rake(1)</a> manual:</p>
179
+ <pre><code>binman-rake --help
180
+ </code></pre>
181
+ <h4 id="Inside-a-Ruby-script">Inside a Ruby script</h4><p>Add this snippet to your gemspec file:</p>
182
+ <pre><code>s.files += Dir[&#39;man/man?/*.?&#39;] # UNIX man pages
183
+ s.files += Dir[&#39;man/**/*.{html,css,js}&#39;] # HTML man pages
184
+ s.add_development_dependency &#39;md2man&#39;, &#39;~&gt; 2.0&#39;
185
+ </code></pre>
186
+ <p>Add the following line to your Rakefile:</p>
187
+ <pre><code>require &#39;binman/rakefile&#39;
188
+ </code></pre>
189
+ <p>You now have a <code>rake binman</code> task that pre-builds UNIX manual page files for
190
+ your <code>bin/</code> scripts into a <code>man/</code> directory so that your end-users do not need
191
+ <a href="https://github.com/sunaku/md2man">md2man</a> installed in order to view the manual pages you&#39;ve embedded therein!
192
+ There are also sub-tasks to build manual pages individually as <a href="http://troff.org">roff</a> or HTML.</p><p>If you&#39;re using Bundler, this task also hooks into its gem packaging tasks and
193
+ ensures that your UNIX manual pages are pre-built and packaged into your gem:</p>
194
+ <pre><code>bundle exec rake build
195
+ gem spec pkg/*.gem | fgrep man/man
196
+ </code></pre>
197
+ <h2 id="License">License</h2><p>Released under the ISC license. See the LICENSE file for details.</p></div></body>
198
+ </html>
@@ -0,0 +1,254 @@
1
+ # binman - man pages for bin scripts
2
+
3
+ [binman] produces UNIX manual pages for executable scripts using [md2man].
4
+
5
+ ## Features
6
+
7
+ * Supports any scripting language that has multi-line
8
+ comments or uses `#` for single-line comments: Ruby,
9
+ Perl, Python, Node.js, Tcl, AWK, UNIX shell, and more!
10
+
11
+ * Provides a Ruby library and a command-line client too.
12
+
13
+ * Individual extraction, conversion, and display commands.
14
+
15
+ * Implemented in roughly 100 lines of pure Ruby code! :-)
16
+
17
+ ### Demonstration
18
+
19
+ ![Obligatory screen-shot of binman(1) in action!](http://ompldr.org/vYm5mcg)
20
+
21
+ Here is [a complete example in Ruby][binman-bin] to help you get started.
22
+ For examples in other scripting languages, see the "Usage" section below!
23
+
24
+ ## Installation
25
+
26
+ If you only want to view pre-built manual pages:
27
+
28
+ gem install binman
29
+
30
+ If you also want to build your own manual pages:
31
+
32
+ gem install md2man -v '~> 1.4'
33
+
34
+ ### Prerequisites
35
+
36
+ * Ruby 1.8.7 or 1.9.2 or newer.
37
+
38
+ ### Development
39
+
40
+ git clone git://github.com/sunaku/binman
41
+ cd binman
42
+ bundle install
43
+ bundle exec binman --help # run it directly
44
+ bundle exec rake --tasks # packaging tasks
45
+
46
+ ## Usage
47
+
48
+ ### At the command line
49
+
50
+ See binman(1) manual:
51
+
52
+ binman --help
53
+
54
+ ### Inside a Ruby script
55
+
56
+ #!/usr/bin/env ruby
57
+ # your program's manual page goes here
58
+
59
+ require 'binman'
60
+
61
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
62
+ BinMan.help
63
+
64
+ # OPTION 2: show manual unconditionally
65
+ BinMan.show
66
+
67
+ You can also specify your program's source file encoding above the manual:
68
+
69
+ #!/usr/bin/env ruby
70
+ # -*- coding: utf-8 -*-
71
+ # your program's manual page goes here
72
+
73
+ You can also write the manual as a multi-line Ruby comment:
74
+
75
+ #!/usr/bin/env ruby
76
+ =begin
77
+ your program's manual page goes here
78
+ =end
79
+
80
+ You can also specify your program's source file encoding above the manual:
81
+
82
+ #!/usr/bin/env ruby
83
+ # -*- coding: utf-8 -*-
84
+ =begin
85
+ your program's manual page goes here
86
+ =end
87
+
88
+ See the [API documentation][binman-api] for even more possibilities!
89
+
90
+ ### Inside a shell script
91
+
92
+ #!/usr/bin/sh
93
+ # your program's manual page goes here
94
+
95
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
96
+ binman help "$0" "$@" && exit
97
+
98
+ # OPTION 2: show manual unconditionally
99
+ binman show "$0"
100
+
101
+ ### Inside a Perl script
102
+
103
+ #!/usr/bin/env perl
104
+ # your program's manual page goes here
105
+
106
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
107
+ system('binman', 'help', __FILE__, @ARGV) == 0 and exit;
108
+
109
+ # OPTION 2: show manual unconditionally
110
+ system('binman', 'show', __FILE__);
111
+
112
+ You can also write the manual as a multi-line Ruby comment after `__END__`:
113
+
114
+ #!/usr/bin/env perl
115
+ print "your program's code goes here";
116
+ __END__
117
+ =begin
118
+ your program's manual page goes here
119
+ =end
120
+
121
+ ### Inside a Python script
122
+
123
+ #!/usr/bin/env python
124
+ # your program's manual page goes here
125
+
126
+ import sys, subprocess
127
+
128
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
129
+ subprocess.call(['binman', 'help', __file__] + sys.argv) == 0 and sys.exit()
130
+
131
+ # OPTION 2: show manual unconditionally
132
+ subprocess.call(['binman', 'show', __file__])
133
+
134
+ You can also specify your program's source file encoding above the manual:
135
+
136
+ #!/usr/bin/env python
137
+ # -*- coding: utf-8 -*-
138
+ # your program's manual page goes here
139
+
140
+ You can also write the manual as a multi-line Ruby comment inside a docstring:
141
+
142
+ #!/usr/bin/env python
143
+ """
144
+ =begin
145
+ your program's manual page goes here
146
+ =end
147
+ """
148
+
149
+ You can also specify your program's source file encoding above the manual:
150
+
151
+ #!/usr/bin/env python
152
+ # -*- coding: utf-8 -*-
153
+ """
154
+ =begin
155
+ your program's manual page goes here
156
+ =end
157
+ """
158
+
159
+ ### Inside an AWK script
160
+
161
+ The technique for determining current AWK script file name [comes from here](
162
+ http://www.mombu.com/programming/programming/t-the-name-of-script-itself-2040784-print.html
163
+ ).
164
+
165
+ #!/usr/bin/awk -f
166
+ # your program's manual page goes here
167
+
168
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
169
+ BEGIN {getline c <"/proc/self/cmdline"; sub(".*-f\0"," ",c); gsub("\0"," ",c);
170
+ if(system("binman help" c) == 0){ exit }}
171
+
172
+ # OPTION 2: show manual unconditionally
173
+ BEGIN {getline c <"/proc/self/cmdline"; sub(".*-f\0"," ",c); sub("\0.*","",c);
174
+ system("binman show" c)}
175
+
176
+ ### Inside a Tcl script
177
+
178
+ #!/usr/bin/env tclsh
179
+ # your program's manual page goes here
180
+
181
+ # OPTION 1: show manual and exit if ARGV has -h or --help except after --
182
+ if {![catch {exec -- >/dev/tty binman help $argv0 {*}$argv}]} {exit}
183
+
184
+ # OPTION 2: show manual unconditionally
185
+ exec >/dev/tty binman show $argv0
186
+
187
+ You can also write the manual as a multi-line Ruby comment inside an `if 0`:
188
+
189
+ #!/usr/bin/env tclsh
190
+ if 0 {
191
+ =begin
192
+ your program's manual page goes here
193
+ =end
194
+ }
195
+
196
+ ### Inside a Node.js script
197
+
198
+ /*
199
+ =begin
200
+ your program's manual page goes here
201
+ =end
202
+ */
203
+
204
+ var exec = require('child_process').exec;
205
+
206
+ // OPTION 1: show manual and exit if ARGV has -h or --help except after --
207
+ exec(['>/dev/tty', 'binman', 'help', __filename].concat(process.argv).
208
+ join(' '), function(error){ if (error === null){ process.exit(); } });
209
+
210
+ // OPTION 2: show manual unconditionally
211
+ exec(['>/dev/tty', 'binman', 'show', __filename].join(' '));
212
+
213
+ ## Packaging
214
+
215
+ ### Building man pages
216
+
217
+ #### At the command line
218
+
219
+ See binman-rake(1) manual:
220
+
221
+ binman-rake --help
222
+
223
+ #### Inside a Ruby script
224
+
225
+ Add this snippet to your gemspec file:
226
+
227
+ s.files += Dir['man/man?/*.?'] # UNIX man pages
228
+ s.files += Dir['man/**/*.{html,css,js}'] # HTML man pages
229
+ s.add_development_dependency 'md2man', '~> 2.0'
230
+
231
+ Add the following line to your Rakefile:
232
+
233
+ require 'binman/rakefile'
234
+
235
+ You now have a `rake binman` task that pre-builds UNIX manual page files for
236
+ your `bin/` scripts into a `man/` directory so that your end-users do not need
237
+ [md2man] installed in order to view the manual pages you've embedded therein!
238
+ There are also sub-tasks to build manual pages individually as [roff] or HTML.
239
+
240
+ If you're using Bundler, this task also hooks into its gem packaging tasks and
241
+ ensures that your UNIX manual pages are pre-built and packaged into your gem:
242
+
243
+ bundle exec rake build
244
+ gem spec pkg/*.gem | fgrep man/man
245
+
246
+ ## License
247
+
248
+ Released under the ISC license. See the LICENSE file for details.
249
+
250
+ [roff]: http://troff.org
251
+ [binman]: https://github.com/sunaku/binman
252
+ [binman-api]: http://rubydoc.info/gems/binman/frames
253
+ [binman-bin]: https://raw.github.com/sunaku/binman/master/bin/binman
254
+ [md2man]: https://github.com/sunaku/md2man