noms-command 0.5.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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +191 -0
  5. data/README.rst +376 -0
  6. data/ROADMAP.rst +127 -0
  7. data/Rakefile +49 -0
  8. data/TODO.rst +7 -0
  9. data/bin/noms2 +20 -0
  10. data/fixture/dnc.rb +120 -0
  11. data/fixture/identity +5 -0
  12. data/fixture/public/dnc.json +22 -0
  13. data/fixture/public/echo.json +7 -0
  14. data/fixture/public/files/data.json +12 -0
  15. data/fixture/public/files/foo.json +2 -0
  16. data/fixture/public/lib/dnc.js +81 -0
  17. data/fixture/public/lib/noms-args.js +13 -0
  18. data/fixture/public/lib/showopt.js +18 -0
  19. data/fixture/public/location.json +8 -0
  20. data/fixture/public/showopt.json +15 -0
  21. data/fixture/rig2json +21 -0
  22. data/lib/noms/command/application.rb +204 -0
  23. data/lib/noms/command/auth/identity.rb +62 -0
  24. data/lib/noms/command/auth.rb +117 -0
  25. data/lib/noms/command/base.rb +22 -0
  26. data/lib/noms/command/document.rb +59 -0
  27. data/lib/noms/command/error.rb +11 -0
  28. data/lib/noms/command/formatter.rb +178 -0
  29. data/lib/noms/command/urinion/data.rb +63 -0
  30. data/lib/noms/command/urinion.rb +29 -0
  31. data/lib/noms/command/useragent.rb +134 -0
  32. data/lib/noms/command/version.rb +7 -0
  33. data/lib/noms/command/window.rb +95 -0
  34. data/lib/noms/command/xmlhttprequest.rb +181 -0
  35. data/lib/noms/command.rb +107 -0
  36. data/noms-command.gemspec +30 -0
  37. data/spec/01noms-command_spec.rb +30 -0
  38. data/spec/02noms-command.sh +31 -0
  39. data/spec/03application_spec.rb +47 -0
  40. data/spec/04application_spec.rb +61 -0
  41. data/spec/05formatter_spec.rb +195 -0
  42. data/spec/06urinion_data.rb +20 -0
  43. data/spec/07js_spec.rb +87 -0
  44. data/spec/08xhr_spec.rb +209 -0
  45. data/spec/09bookmarks_spec.rb +60 -0
  46. data/spec/10auth_spec.rb +33 -0
  47. data/spec/spec_helper.rb +40 -0
  48. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bcefa4ec6a121ab3dc7f9be3c7242a87f58203c
4
+ data.tar.gz: f12c00d11f170af8cb53f4ed3349d20d9ee74505
5
+ SHA512:
6
+ metadata.gz: f6d50e6bb50f761f49f766ffec47db3c8fbddadcc55cfa78223c99ffb2ceffcced639cc08e5a299d1bdcf3c11035cb337da761db5e3eb39532b40724bd465213
7
+ data.tar.gz: 5c4e2f8970d23764a8cfabe04448748c2f9f717b16bd8073808ad35ca1b377b6f6558e113a99fe487b2540ffd6b57067055545b477e63084d4edf3fca279faa8
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /test/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in noms-command.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/README.rst ADDED
@@ -0,0 +1,376 @@
1
+ noms
2
+ ====
3
+
4
+ **Script The Service-Oriented Architecture**
5
+
6
+ **noms** is a remote command-line interface interpreter. It's designed
7
+ to be a stable runtime environment for interpreting server-defined
8
+ command-line interfaces for (principally) rest-like data stores (or
9
+ for commands that are side-effect free, but *not* commands that
10
+ change any state on the system on which the command runs).
11
+
12
+ The web browser is a platform in which the operator of a web service
13
+ can implement a graphical user interface to data it controls. For
14
+ example, it's a common pattern to offer access to services and data
15
+ via a ReST or ReST-like interface, making http requests against a
16
+ remote API understanding the HTTP verbs and returning results in the
17
+ form of HTTP responses, header metadata and response bodies containing
18
+ serialized data (e.g. JSON). Such interfaces are generally implemented
19
+ in a combination of HTML documents and Javascript which modifies the
20
+ document model of the HTML page(s).
21
+
22
+ **noms** enables an author to offer a command-line interface designed
23
+ along the same pattern: structured documents modified by javascript
24
+ programs, interpreted and rendered on the client. **noms** has
25
+ sandboxing similar to web browsers (no modifying of local storage
26
+ outside of restricted, application-specific local storage and
27
+ automatic caching of javascript files).
28
+
29
+ **noms** is *not* a web browser and is not designed to offer terminal
30
+ user interfaces like lynx or elinks. It is also *not* an interactive
31
+ shell--it's designed to be used from a shell. It maintains
32
+ authenticated session state when necessary. It is *not* a wget_
33
+ or curl_ replacement but it can be useful for discovering and
34
+ using ReST data stores.
35
+
36
+ .. _wget: https://www.gnu.org/s/wget
37
+
38
+ .. _curl: http://curl.haxx.se/
39
+
40
+ The name **noms** comes from `New Operations Management Stack`_
41
+ because its principal and first use is as a CLI and scripting
42
+ component for the various network-accessible APIs comprising that
43
+ project. It is, in part, a future replacement for noms-client_ as it
44
+ solves some of the software distribution and local configuration
45
+ issues caused by that command (though it's likely the NOMS component
46
+ client libraries will remain).
47
+
48
+ .. _`New Operations Management Stack`: https://github.com/evernote/noms-client/wiki
49
+
50
+ .. _noms-client: https://github.com/evernote/noms-client
51
+
52
+ Syntax
53
+ ------
54
+
55
+ The basic way of invoking a **noms** command is as follows::
56
+
57
+ noms *url* *options* *arguments*
58
+
59
+ **noms** invokes the app at *url* with the given options and
60
+ arguments, displaying the results.
61
+
62
+ **noms** has its own options, which can be given before the
63
+ *url*, and are available when invoking ``noms --help`.
64
+
65
+ Bookmarks
66
+ ~~~~~~~~~
67
+
68
+ * ``noms *bookmark*[/arg] ...``
69
+
70
+ **noms** bookmarks are stored, by default, in ``~/.noms/bookmarks.json``,
71
+ ``/usr/local/etc/noms/bookmarks.json``, and ``/etc/noms/bookmarks.json``
72
+ (in that order). These are strict correspondences between a short
73
+ alias and a URL to load for an app::
74
+
75
+ {
76
+ "cmdb": "https://cmdb.noms-example.com/cmdb.json",
77
+ "instance": "https://ncc-api.noms-example.com/ncc-api.json",
78
+ "nagios": "https://nagios.noms-example.com/nagui.json",
79
+ "nag": "https://nagios.noms-exmaple.com/nagui.json"
80
+ }
81
+
82
+ Additional bookmark sources can be given with the ``bookmarks`` option. All
83
+ bookmarks from valid sources are merged.
84
+
85
+ When invoked in the following ways, it's the equivalent to the command on the right:
86
+
87
+ ================================= ==================================================================
88
+ Command given Equivalent command
89
+ ================================= ==================================================================
90
+ ``noms cmdb query fqdn~^m00`` ``noms https://cmdb.noms-example.com/cmdb.json query fqdn~^m00``
91
+ (``document.argv[0]`` set to ``cmdb``)
92
+ ``noms cmdb/env list`` ``noms https://cmdb.noms-example.com/cmdb.json list``
93
+ (``document.argv[0]`` set to ``cmdb/env``)
94
+ ``noms nag alerts`` ``noms https://cmdb.noms-example.com/nagui.json alerts``
95
+ (``document.argv[0]`` set to ``nag``)
96
+ ================================= ==================================================================
97
+
98
+ This will probably be the limit of **noms'** client-side
99
+ configuration. Other things like cache directories and authentication
100
+ strictness policies may be configurable in a file, but the point of
101
+ **noms** is to remove the distribution of thick client libraries that
102
+ try to abstract away server-side interfaces and the configurations
103
+ they require, so it would defeat part of its purpose to allow rich
104
+ configuration of things like default values for objects and so forth.
105
+
106
+ Implementation
107
+ --------------
108
+
109
+ When **noms** retrieves an application URL, it uses the following
110
+ logic to determine how to output the result.
111
+
112
+ If the type is ``text/*``, it's simply displayed.
113
+
114
+ If the type is a recognized data serialization format (basically,
115
+ ``application/json`` or ``application/yaml``), it's parsed as
116
+ structured data. If the fetched content is a single object and the
117
+ object has the top-level key '$doctype', it may be interpreted
118
+ according to `Dynamic Doctype`_, below. Otherwise, it is assumed to be
119
+ structured list or object data, and **noms** will render the object or
120
+ array using its default format (usually YAML).
121
+
122
+ Authentication
123
+ --------------
124
+
125
+ *NOTE:* This is under active development, expect it to change
126
+ frequently.
127
+
128
+ **noms** supports Basic authentication. It will prompt the user for
129
+ a username and password when required. A saved identity file can be
130
+ provided with the ``--identity`` option to **noms** for non-interactive
131
+ use.
132
+
133
+ Dynamic Doctype
134
+ ~~~~~~~~~~~~~~~
135
+
136
+ The dynamic doctype is the ``noms-v2`` type, which is an object with
137
+ the following top-level attributes:
138
+
139
+ ``$doctype``
140
+ Must be ``noms-v2``. In future, backwards-incompatible extensions may be implemented in ``noms-v3`` or higher doctypes.
141
+
142
+ ``$script``
143
+ An ordered array of scripts to fetch and evaluate; or Javascript text to evaluate directly.
144
+
145
+ ``$argv``
146
+ The arguments passed to the application. It's called ``$argv``
147
+ because ``$argv[0]`` contains the name by which the application is
148
+ invoked (that is, the bookmark or URL).
149
+
150
+ ``$exitcode``
151
+ The unix process exit code with which **noms** will exit at the completion of the command.
152
+
153
+ ``$body``
154
+ The body of the document is the data to display. See `Output Formatting`_ below.
155
+
156
+ From the perspective of javascript executing within the application,
157
+ these are accessible as properties of the global **document** object
158
+ (e.g., ``document.argv`` is the array of arguments given on the **noms**
159
+ command line; Javascript can set ``document.exitcode`` to determine
160
+ **noms'** exit code.
161
+
162
+ Output Formatting
163
+ ~~~~~~~~~~~~~~~~~
164
+
165
+ The following entities are allowed in the body of a **noms-v2** document:
166
+
167
+ * Arrays - Each item in the array is concatenated with a line-break
168
+ between them.
169
+ * Strings and numbers - A string or number is just displayed.
170
+ * Raw objects - Raw objects are rendered using **noms'** default
171
+ formatting (usually YAML)
172
+ * Described objects - Described objects are data, along with
173
+ information on how to render them. A described object has a
174
+ top-level attribute called **$type** which defines how the described
175
+ object is rendered.
176
+
177
+ * ``$type``: **object-list** An object list is a (usually) tabular
178
+ list of objects with information on how wide to make the fields or
179
+ how to otherwise serialize the objects. It has the following
180
+ attributes:
181
+
182
+ * **format**: The format in which to render, one of: **json**,
183
+ **yaml**, **csv**, **lines** (default **lines**). The **lines**
184
+ format is **noms'** built-in presentation of tabular data
185
+ (similar to typical Unix command output).
186
+
187
+ * **columns**: An array of column specifiers. A column specifier
188
+ is either a string with the name of the field to display, or an
189
+ object which has the following attributes:
190
+
191
+ * **field**: The object field to display in the column (*required*)
192
+
193
+ * **heading**: The label to display in the column heading
194
+
195
+ * **width**: The width of the column (data is space-padded to this width)
196
+
197
+ * **align**: One of ``left`` or ``right``, determines data
198
+ alignment within column
199
+
200
+ * **maxwidth**: The maximum width of the data (values exceeding
201
+ this length are truncated)
202
+
203
+ * **labels**: Default ``true``; whether to display header row with field labels
204
+
205
+ * **columns**: Field names, headings and widths
206
+
207
+ * **data**: The objects to render
208
+
209
+ * ``$type``: **object** An object has the following attributes:
210
+
211
+ * **format**: The format in which to render, one of: **json**,
212
+ **yaml**, **record** (default **record**). The **record**
213
+ format is **noms'** built-in presentation of record data.
214
+
215
+ * **fields**: The fields to display (default is all fields)
216
+
217
+ * **labels**: Default ``true``, whether to display field labels
218
+
219
+ * **data**: The object data
220
+
221
+ Javascript Environment
222
+ ----------------------
223
+
224
+ Scripts have access to the following global objects:
225
+
226
+ * **window** - This has information about the terminal environment in
227
+ which **noms** is being invoked. It has the following
228
+ attributes/methods:
229
+
230
+ * **isatty** - true if the output stream is a terminal
231
+
232
+ * **document** - The document global object
233
+
234
+ * **location** - The location global object
235
+
236
+ * **console** - The console object implements **console.log** for
237
+ printing output to the debug stream (visible when the noms option
238
+ ``--debug`` is given.
239
+
240
+ * **alert()** - Produce output on the error stream
241
+
242
+ * **prompt()** - Prompt the user for input. You can pass a second
243
+ argument, which is a boolean value for whether the user input
244
+ should be echoed.
245
+
246
+ * **document** - The document object is the current document being
247
+ rendered by **noms**. These properties are assignable but the objects
248
+ behind them are immutable. In addition to the attributes of the document
249
+ itself, it has the following:
250
+
251
+ * **argv** - The arguments being invoked. The first element of this
252
+ array is the first argument passed to **noms** itself (not the
253
+ script it ultimately fetches, but how it's invoked, similar to
254
+ ``$1``.
255
+
256
+ * **exitcode** - The numeric exit code with which **noms** will
257
+ exit. Initially 0.
258
+
259
+ * **body** - The text to display according to NOMS formattting.
260
+
261
+ * **XMLHttpRequest** - A partial implementation of the XMLHttpRequest
262
+ interface. See `NOMS::Command::XMLHttpRequest`_ for details. This
263
+ implementation conforms to a same-origin policy.
264
+
265
+ .. _`NOMS::Command::XMLHttpRequest`: http://www.rubydoc.info/gems/noms-command/NOMS/Command/XMLHttpRequest
266
+
267
+
268
+ Web 1.0 vs Web 2.0
269
+ ------------------
270
+
271
+ Like the "real web", **noms** commands can choose to do some
272
+ calculation on the server and some on the client: **noms** doesn't
273
+ care. You can use no ``$script`` tag at all and just calculate the
274
+ entire document to be rendered in the client (though this currently
275
+ doesn't allow for argument interpretation, in the future the
276
+ arguments may be passed in request headers or **noms** may allow a way
277
+ for them to show up in a query string or POST request--but **noms** is
278
+ not really a command-line http client either). This is up to the
279
+ application designer.
280
+
281
+ Example Application
282
+ -------------------
283
+
284
+ In the source code repository is an example **noms** application,
285
+ **dnc** (a "do not call" list). The following is an example session
286
+ with **dnc**::
287
+
288
+ bash$ noms http://localhost:8787/dnc.json
289
+ Usage:
290
+ noms dnc add <field>=<value> [<field>=<value> [...]]
291
+ noms dnc remove <id>
292
+ noms check { <phone> | <name> }
293
+ noms list
294
+ bash$ noms http://localhost:8787/dnc.json list
295
+ name phone
296
+ Manuela Irwin (817) 555-0427
297
+ Ronda Sheppard (401) 555-0801
298
+ Leonor Foreman (401) 555-0428
299
+ Emma Roman (317) 555-0589
300
+ Frieda English (312) 555-0930
301
+ Kitty Morton (804) 555-0618
302
+ Kathy Mcleod (607) 555-0052
303
+ Bettie Wolfe (843) 555-0523
304
+ Vanessa Conway (404) 555-0885
305
+ Ian Welch (817) 555-0555
306
+ 10 objects
307
+ bash$ curl http://localhost:8787/dnc.json
308
+ { "$doctype": "noms-v2",
309
+ "$script": [{ "$source": "lib/commands.js" }],
310
+ "$body": [
311
+ "Usage:",
312
+ " noms dnc add <field>=<value> [<field>=<value> [...]]",
313
+ " noms dnc remove <id>",
314
+ " noms check { <phone> | <name> }",
315
+ " noms list"
316
+ ]
317
+ }
318
+ bash$ curl http://localhost:8787/lib/commands.js
319
+ if (document.argv.length > 1) {
320
+ var command = document.argv[1];
321
+ var xmlhttp = new XMLHttpRequest();
322
+
323
+ switch(command) {
324
+ case "list":
325
+ // unimplemented callbacks
326
+ xmlhttp.open("GET", "/dnc", false);
327
+ xmlhttp.send();
328
+ var records = eval('(' + xmlhttp.responseText + ')');
329
+ // Set the 'output' to the format specifier that
330
+ // tells noms to produce an object list output
331
+ document.body = [
332
+ {
333
+ '$type': 'object-list',
334
+ '$columns': [
335
+ { 'field': 'name', 'width': 20 },
336
+ { 'field': 'phone', 'width': 20 }
337
+ ],
338
+ '$data': records
339
+ },
340
+ records.length + " objects"
341
+ ];
342
+ break;
343
+ default:
344
+ document.exitcode = 8;
345
+ // need errors and warnings
346
+ document.body = [
347
+ document.argv[0] + ": Unknown command '" + command + "'"
348
+ ];
349
+ }
350
+ }
351
+ bash$ curl http://localhost:8787/files/data.json
352
+ [
353
+ {"id":1,"name":"Manuela Irwin","street":"427 Maple Ln","city":"Arlington, TX 76010","phone":"(817) 555-0427"},
354
+ {"id":2,"name":"Ronda Sheppard","street":"801 New First Rd","city":"Providence, RI 02940","phone":"(401) 555-0801"},
355
+ {"id":3,"name":"Leonor Foreman","street":"428 Willow Rd","city":"Providence, RI 02940","phone":"(401) 555-0428"},
356
+ {"id":4,"name":"Emma Roman","street":"589 Flanty Terr","city":"Anderson, IN 46018","phone":"(317) 555-0589"},
357
+ {"id":5,"name":"Frieda English","street":"930 Stonehedge Blvd","city":"Chicago, IL 60607","phone":"(312) 555-0930"},
358
+ {"id":6,"name":"Kitty Morton","street":"618 Manchester St","city":"Richmond, VA 23232","phone":"(804) 555-0618"},
359
+ {"id":7,"name":"Kathy Mcleod","street":"52 Wommert Ln","city":"Binghamton, NY 13902","phone":"(607) 555-0052"},
360
+ {"id":8,"name":"Bettie Wolfe","street":"523 Sharon Rd","city":"Coward, SC 29530","phone":"(843) 555-0523"},
361
+ {"id":9,"name":"Vanessa Conway","street":"885 Old Pinbrick Dr","city":"Athens, GA 30601","phone":"(404) 555-0885"},
362
+ {"id":10,"name":"Ian Welch","street":"555 Hamlet St","city":"Arlington, TX 76010","phone":"(817) 555-0555"}
363
+ ]
364
+
365
+ The example application is a very simple sinatra REST API to a data
366
+ store consisting of a JSON file, and the static files comprising the
367
+ Javascript source code and the **noms** application document.
368
+
369
+ Running Examples
370
+ ----------------
371
+
372
+ Use ``rake start`` to start the test webserver and run the
373
+ example applications (see the comments inside the
374
+ ``fixture/public/*.json`` files for syntax).
375
+
376
+ Start with ``noms2 http://localhost:8787/echo.json hello world``.