Skip to content

Commit

Permalink
Added README, LICENSE and better no-url handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Oct 23, 2013
1 parent ca0dfab commit 37a1e83
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
39 changes: 39 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Copyright 2013, Matteo Collina (the "Original Author")
All rights reserved.

MIT +no-false-attribs License

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

Distributions of all or part of the Software intended to be used
by the recipients as they would use the unmodified Software,
containing modifications that substantially alter, remove, or
disable functionality of the Software, outside of the documented
configuration mechanisms provided by the Software, shall be
modified such that the Original Author's bug reporting email
addresses and urls are either replaced with the contact information
of the parties responsible for the changes, or removed entirely.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


Except where noted, this license applies to any and all software
programs and associated documentation files created by the
Original Author, when distributed with the Software.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CoAP-CLI
============================

[![Build
Status](https://travis-ci.org/mcollina/coap-cli.png)](https://travis-ci.org/mcollina/coap-cli)

__CoAP-CLI__ is a command line interface for CoAP, built on node.js and
[node-coap](http://github.com/mcollina/node-coap).

What is CoAP?
----------------------------

> Constrained Application Protocol (CoAP) is a software protocol
intended to be used in very simple electronics devices that allows them
to communicate interactively over the Internet. - Wikipedia

Usage
----------------------------

```
Usage: coap [options] url
Options:
-h, --help output usage information
-V, --version output the version number
-n, --no-new-line No new line at the end of the stream
```

License
----------------------------

Copyright (c) 2013 Matteo Collina

node-coap is licensed under an MIT +no-false-attribs license.
All rights not explicitly granted in the MIT license are reserved.
See the included LICENSE file for more details.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ var program = require('commander')
, version = require('./package').version
, request = require('coap').request


program
.version(version)
.option('-n, --no-new-line', 'No new line at the end of the stream', 'boolean', true)
.usage('[options] url')
.parse(process.argv)

if (!program.args[0]) {
program.outputHelp()
process.exit(-1)
}

request(program.args[0]).on('response', function(res) {
res.pipe(process.stdout)

if (program.newLine)
if (res.code !== '4.04' && program.newLine)
res.on('end', function() {
process.stdout.write('\n')
})
Expand Down
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,23 @@ describe('coap', function() {
res.end('hello matteo')
})
})

it('should print help if no url', function(done) {
call().stdout.pipe(concat(function(data) {
expect(data.toString()).to.match(/Usage/)
done()
}))
})

it('should should not emit a new line if the response was a 4.04', function(done) {
call('coap://localhost').stdout.pipe(concat(function(data) {
expect(data).to.equal(undefined)
done()
}))

server.once('request', function(req, res) {
res.statusCode = 404
res.end()
})
})
})

0 comments on commit 37a1e83

Please sign in to comment.