-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
118 lines (93 loc) · 3.59 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>docopt—language for description of command-line interfaces</title>
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<a href="https://github.com/docopt/challenge.docopt.org"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<h1>docopt</h1>
<h2>Challenge</h2>
<h3>How many LOC will you require to implement a CLI interface like that?</h3>
<pre><code>Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate -h | --help
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
</code></pre>
<p><br><br></p>
<h2>Rules</h2>
<ol>
<li><p>Any programming language.</p></li>
<li><p>Any command line arguments parsing library.</p></li>
<li><p>Your program should allow only the usage described above.</p></li>
<li><p>Your program should display the usage and exit if invoked incorrectly.</p></li>
<li><p>Your program should print a collection (object, hash, alist, etc.) of
the above mentioned <em>commands</em>, <em>options</em>, <em>arguments</em> and their values.</p></li>
<li><p>Describe how to run your code.</p></li>
<li><p>Post solution to <a href="http://news.ycombinator.com/item?id=4122547">Hacker News thread</a>.</p></li>
<li><p>Have fun!</p></li>
</ol>
<h1>docopt</h1>
<h2>Solution</h2>
<h3><a href="http://github.com/docopt/docopt">In Python</a></h3>
<pre><code>#! /usr/bin/env python
"""Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate -h | --help
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
"""
from docopt import docopt
print docopt(__doc__, version='Naval Fate 2.0')
</code></pre>
<h3><a href="http://github.com/docopt/docopt.coffee">In CoffeeScript</a></h3>
<pre><code>#! /usr/bin/env coffee
doc = """Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate -h | --help
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
"""
{docopt} = require '../docopt'
console.log docopt(doc, version: 'Naval Fate 2.0')
</code></pre>
<h3><a href="http://www.docopt.org">www.docopt.org</a></h3>
<p><br></p>
<script>
var _gaq=[['_setAccount','UA-15242420-3'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>