cli-pasta 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.md +192 -0
- data/README.md +122 -0
- data/lib/cli-pasta.rb +6 -0
- data/lib/cli-pasta/epipe.rb +4 -0
- data/lib/cli-pasta/sigint.rb +4 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5612e4030cb2f485f5bb1a6c00b5f8f3ddfa4617d0b21f72492cbc0f1ea38397
|
4
|
+
data.tar.gz: 2d01a19cc92baf44ef1c80b6e0a629b27660c7410702f215eb8dab826edb5f85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65687bfac89d2d948b2838f7af257f58ee8df94e622ba7e177077b005f709cbff2a2e396d04ce5c0d969877727262ba539317c105c778d3ac2bcae8f4f7b268f
|
7
|
+
data.tar.gz: 8f92137c9bb38481212aac5de6c6a350a1cd95518ce93498f962440e1c70c35baadef2113c1b0733f69b1e5a3b66d6b5e0a4d22cc5d01a9223ce31f84434588e
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
The Artistic License 2.0
|
2
|
+
========================
|
3
|
+
|
4
|
+
_Copyright © 2000-2006, The Perl Foundation._
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
7
|
+
of this license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
### Preamble
|
10
|
+
|
11
|
+
This license establishes the terms under which a given free software
|
12
|
+
Package may be copied, modified, distributed, and/or redistributed.
|
13
|
+
The intent is that the Copyright Holder maintains some artistic
|
14
|
+
control over the development of that Package while still keeping the
|
15
|
+
Package available as open source and free software.
|
16
|
+
|
17
|
+
You are always permitted to make arrangements wholly outside of this
|
18
|
+
license directly with the Copyright Holder of a given Package. If the
|
19
|
+
terms of this license do not permit the full use that you propose to
|
20
|
+
make of the Package, you should contact the Copyright Holder and seek
|
21
|
+
a different licensing arrangement.
|
22
|
+
|
23
|
+
### Definitions
|
24
|
+
|
25
|
+
“Copyright Holder” means the individual(s) or organization(s)
|
26
|
+
named in the copyright notice for the entire Package.
|
27
|
+
|
28
|
+
“Contributor” means any party that has contributed code or other
|
29
|
+
material to the Package, in accordance with the Copyright Holder's
|
30
|
+
procedures.
|
31
|
+
|
32
|
+
“You” and “your” means any person who would like to copy,
|
33
|
+
distribute, or modify the Package.
|
34
|
+
|
35
|
+
“Package” means the collection of files distributed by the
|
36
|
+
Copyright Holder, and derivatives of that collection and/or of
|
37
|
+
those files. A given Package may consist of either the Standard
|
38
|
+
Version, or a Modified Version.
|
39
|
+
|
40
|
+
“Distribute” means providing a copy of the Package or making it
|
41
|
+
accessible to anyone else, or in the case of a company or
|
42
|
+
organization, to others outside of your company or organization.
|
43
|
+
|
44
|
+
“Distributor Fee” means any fee that you charge for Distributing
|
45
|
+
this Package or providing support for this Package to another
|
46
|
+
party. It does not mean licensing fees.
|
47
|
+
|
48
|
+
“Standard Version” refers to the Package if it has not been
|
49
|
+
modified, or has been modified only in ways explicitly requested
|
50
|
+
by the Copyright Holder.
|
51
|
+
|
52
|
+
“Modified Version” means the Package, if it has been changed, and
|
53
|
+
such changes were not explicitly requested by the Copyright
|
54
|
+
Holder.
|
55
|
+
|
56
|
+
“Original License” means this Artistic License as Distributed with
|
57
|
+
the Standard Version of the Package, in its current version or as
|
58
|
+
it may be modified by The Perl Foundation in the future.
|
59
|
+
|
60
|
+
“Source” form means the source code, documentation source, and
|
61
|
+
configuration files for the Package.
|
62
|
+
|
63
|
+
“Compiled” form means the compiled bytecode, object code, binary,
|
64
|
+
or any other form resulting from mechanical transformation or
|
65
|
+
translation of the Source form.
|
66
|
+
|
67
|
+
### Permission for Use and Modification Without Distribution
|
68
|
+
|
69
|
+
**(1)** You are permitted to use the Standard Version and create and use
|
70
|
+
Modified Versions for any purpose without restriction, provided that
|
71
|
+
you do not Distribute the Modified Version.
|
72
|
+
|
73
|
+
### Permissions for Redistribution of the Standard Version
|
74
|
+
|
75
|
+
**(2)** You may Distribute verbatim copies of the Source form of the
|
76
|
+
Standard Version of this Package in any medium without restriction,
|
77
|
+
either gratis or for a Distributor Fee, provided that you duplicate
|
78
|
+
all of the original copyright notices and associated disclaimers. At
|
79
|
+
your discretion, such verbatim copies may or may not include a
|
80
|
+
Compiled form of the Package.
|
81
|
+
|
82
|
+
**(3)** You may apply any bug fixes, portability changes, and other
|
83
|
+
modifications made available from the Copyright Holder. The resulting
|
84
|
+
Package will still be considered the Standard Version, and as such
|
85
|
+
will be subject to the Original License.
|
86
|
+
|
87
|
+
### Distribution of Modified Versions of the Package as Source
|
88
|
+
|
89
|
+
**(4)** You may Distribute your Modified Version as Source (either gratis
|
90
|
+
or for a Distributor Fee, and with or without a Compiled form of the
|
91
|
+
Modified Version) provided that you clearly document how it differs
|
92
|
+
from the Standard Version, including, but not limited to, documenting
|
93
|
+
any non-standard features, executables, or modules, and provided that
|
94
|
+
you do at least ONE of the following:
|
95
|
+
|
96
|
+
* **(a)** make the Modified Version available to the Copyright Holder
|
97
|
+
of the Standard Version, under the Original License, so that the
|
98
|
+
Copyright Holder may include your modifications in the Standard
|
99
|
+
Version.
|
100
|
+
* **(b)** ensure that installation of your Modified Version does not
|
101
|
+
prevent the user installing or running the Standard Version. In
|
102
|
+
addition, the Modified Version must bear a name that is different
|
103
|
+
from the name of the Standard Version.
|
104
|
+
* **(c)** allow anyone who receives a copy of the Modified Version to
|
105
|
+
make the Source form of the Modified Version available to others
|
106
|
+
under
|
107
|
+
* **(i)** the Original License or
|
108
|
+
* **(ii)** a license that permits the licensee to freely copy,
|
109
|
+
modify and redistribute the Modified Version using the same
|
110
|
+
licensing terms that apply to the copy that the licensee
|
111
|
+
received, and requires that the Source form of the Modified
|
112
|
+
Version, and of any works derived from it, be made freely
|
113
|
+
available in that license fees are prohibited but Distributor
|
114
|
+
Fees are allowed.
|
115
|
+
|
116
|
+
### Distribution of Compiled Forms of the Standard Version
|
117
|
+
### or Modified Versions without the Source
|
118
|
+
|
119
|
+
**(5)** You may Distribute Compiled forms of the Standard Version without
|
120
|
+
the Source, provided that you include complete instructions on how to
|
121
|
+
get the Source of the Standard Version. Such instructions must be
|
122
|
+
valid at the time of your distribution. If these instructions, at any
|
123
|
+
time while you are carrying out such distribution, become invalid, you
|
124
|
+
must provide new instructions on demand or cease further distribution.
|
125
|
+
If you provide valid instructions or cease distribution within thirty
|
126
|
+
days after you become aware that the instructions are invalid, then
|
127
|
+
you do not forfeit any of your rights under this license.
|
128
|
+
|
129
|
+
**(6)** You may Distribute a Modified Version in Compiled form without
|
130
|
+
the Source, provided that you comply with Section 4 with respect to
|
131
|
+
the Source of the Modified Version.
|
132
|
+
|
133
|
+
### Aggregating or Linking the Package
|
134
|
+
|
135
|
+
**(7)** You may aggregate the Package (either the Standard Version or
|
136
|
+
Modified Version) with other packages and Distribute the resulting
|
137
|
+
aggregation provided that you do not charge a licensing fee for the
|
138
|
+
Package. Distributor Fees are permitted, and licensing fees for other
|
139
|
+
components in the aggregation are permitted. The terms of this license
|
140
|
+
apply to the use and Distribution of the Standard or Modified Versions
|
141
|
+
as included in the aggregation.
|
142
|
+
|
143
|
+
**(8)** You are permitted to link Modified and Standard Versions with
|
144
|
+
other works, to embed the Package in a larger work of your own, or to
|
145
|
+
build stand-alone binary or bytecode versions of applications that
|
146
|
+
include the Package, and Distribute the result without restriction,
|
147
|
+
provided the result does not expose a direct interface to the Package.
|
148
|
+
|
149
|
+
### Items That are Not Considered Part of a Modified Version
|
150
|
+
|
151
|
+
**(9)** Works (including, but not limited to, modules and scripts) that
|
152
|
+
merely extend or make use of the Package, do not, by themselves, cause
|
153
|
+
the Package to be a Modified Version. In addition, such works are not
|
154
|
+
considered parts of the Package itself, and are not subject to the
|
155
|
+
terms of this license.
|
156
|
+
|
157
|
+
### General Provisions
|
158
|
+
|
159
|
+
**(10)** Any use, modification, and distribution of the Standard or
|
160
|
+
Modified Versions is governed by this Artistic License. By using,
|
161
|
+
modifying or distributing the Package, you accept this license. Do not
|
162
|
+
use, modify, or distribute the Package, if you do not accept this
|
163
|
+
license.
|
164
|
+
|
165
|
+
**(11)** If your Modified Version has been derived from a Modified
|
166
|
+
Version made by someone other than you, you are nevertheless required
|
167
|
+
to ensure that your Modified Version complies with the requirements of
|
168
|
+
this license.
|
169
|
+
|
170
|
+
**(12)** This license does not grant you the right to use any trademark,
|
171
|
+
service mark, tradename, or logo of the Copyright Holder.
|
172
|
+
|
173
|
+
**(13)** This license includes the non-exclusive, worldwide,
|
174
|
+
free-of-charge patent license to make, have made, use, offer to sell,
|
175
|
+
sell, import and otherwise transfer the Package with respect to any
|
176
|
+
patent claims licensable by the Copyright Holder that are necessarily
|
177
|
+
infringed by the Package. If you institute patent litigation
|
178
|
+
(including a cross-claim or counterclaim) against any party alleging
|
179
|
+
that the Package constitutes direct or contributory patent
|
180
|
+
infringement, then this Artistic License to you shall terminate on the
|
181
|
+
date that such litigation is filed.
|
182
|
+
|
183
|
+
**(14)** **Disclaimer of Warranty:**
|
184
|
+
|
185
|
+
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
|
186
|
+
IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
|
187
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
188
|
+
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
|
189
|
+
LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
|
190
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
191
|
+
DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
|
192
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# cli-pasta
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/chocolateboy/cli-pasta.svg)](https://travis-ci.org/chocolateboy/cli-pasta)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/cli-pasta.svg)](https://rubygems.org/gems/cli-pasta)
|
5
|
+
[![License](https://img.shields.io/badge/license-artistic-blue.svg)](https://github.com/chocolateboy/cli-pasta/blob/master/LICENSE.md)
|
6
|
+
|
7
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
8
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
9
|
+
|
10
|
+
- [NAME](#name)
|
11
|
+
- [INSTALL](#install)
|
12
|
+
- [SYNOPSIS](#synopsis)
|
13
|
+
- [DESCRIPTION](#description)
|
14
|
+
- [BACKGROUND](#background)
|
15
|
+
- [CLASSES](#classes)
|
16
|
+
- [VERSION](#version)
|
17
|
+
- [SEE ALSO](#see-also)
|
18
|
+
- [AUTHOR](#author)
|
19
|
+
- [COPYRIGHT AND LICENSE](#copyright-and-license)
|
20
|
+
|
21
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
22
|
+
|
23
|
+
# NAME
|
24
|
+
|
25
|
+
cli-pasta - handle Ctrl-C and broken-pipe errors gracefully in Ruby command-line tools
|
26
|
+
|
27
|
+
# INSTALL
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem "cli-pasta"
|
31
|
+
```
|
32
|
+
|
33
|
+
# SYNOPSIS
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
#!/usr/bin/env ruby
|
37
|
+
|
38
|
+
require "cli-pasta"
|
39
|
+
require "optparse"
|
40
|
+
|
41
|
+
# ...
|
42
|
+
|
43
|
+
ARGF.each do |line|
|
44
|
+
puts process(line)
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
# DESCRIPTION
|
49
|
+
|
50
|
+
cli-pasta packages boilerplate code which is commonly copied 'n' pasted into Ruby CLI scripts to perform the following tasks:
|
51
|
+
|
52
|
+
* set up an `EPIPE` handler to handle broken pipes in the same way as other CLI tools
|
53
|
+
* set up a `SIGINT` handler to handle <kbd>Ctrl-C</kbd> in the same way as other CLI tools
|
54
|
+
|
55
|
+
These tasks are executed by loading the corresponding files, either separately e.g.:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require "cli-pasta/epipe"
|
59
|
+
require "cli-pasta/sigint"
|
60
|
+
```
|
61
|
+
|
62
|
+
Or as a group e.g.:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require "cli-pasta"
|
66
|
+
```
|
67
|
+
|
68
|
+
## BACKGROUND
|
69
|
+
|
70
|
+
By default, ruby produces an ugly error message when scripts are interrupted by <kbd>Ctrl-C</kbd> (`SIGINT`) e.g.:
|
71
|
+
|
72
|
+
$ timeout --signal INT 1 ruby -e sleep
|
73
|
+
|
74
|
+
Output:
|
75
|
+
|
76
|
+
^CTraceback (most recent call last):
|
77
|
+
1: from -e:1:in `<main>'
|
78
|
+
-e:1:in `sleep': Interrupt
|
79
|
+
|
80
|
+
The same is true if a process encounters an error when trying to write to a broken pipe (`EPIPE`) e.g.:
|
81
|
+
|
82
|
+
$ ruby -e 'loop { puts "." }' | head -n0
|
83
|
+
|
84
|
+
Output:
|
85
|
+
|
86
|
+
Traceback (most recent call last):
|
87
|
+
5: from -e:1:in `<main>'
|
88
|
+
4: from -e:1:in `loop'
|
89
|
+
3: from -e:1:in `block in <main>'
|
90
|
+
2: from -e:1:in `puts'
|
91
|
+
1: from -e:1:in `puts'
|
92
|
+
-e:1:in `write': Broken pipe @ io_writev - <STDOUT> (Errno::EPIPE)
|
93
|
+
|
94
|
+
The snippets provided by this gem install signal handlers which handle these errors in the same way as other CLI tools e.g.:
|
95
|
+
|
96
|
+
$ timeout --signal INT 1 ruby -r cli-pasta -e sleep
|
97
|
+
# No output
|
98
|
+
|
99
|
+
$ ruby -r cli-pasta -e 'loop { puts "." }' | head -n0
|
100
|
+
# No output
|
101
|
+
|
102
|
+
# CLASSES
|
103
|
+
|
104
|
+
None.
|
105
|
+
|
106
|
+
# VERSION
|
107
|
+
|
108
|
+
1.0.0
|
109
|
+
|
110
|
+
# SEE ALSO
|
111
|
+
|
112
|
+
* [nice-sigint](https://github.com/xiongchiamiov/nice-sigint) - make Ruby handle SIGINTs in a less-ugly manner
|
113
|
+
|
114
|
+
# AUTHOR
|
115
|
+
|
116
|
+
[chocolateboy](mailto:chocolate@cpan.org)
|
117
|
+
|
118
|
+
# COPYRIGHT AND LICENSE
|
119
|
+
|
120
|
+
Copyright © chocolateboy, 2018.
|
121
|
+
|
122
|
+
This gem is free software. It is available under the terms of the [Artistic License 2.0](http://www.opensource.org/licenses/artistic-license-2.0.php).
|
data/lib/cli-pasta.rb
ADDED
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cli-pasta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chocolateboy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: komenda
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.8
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.54.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.54.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tty-which
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.3.0
|
97
|
+
description:
|
98
|
+
email: chocolate@cpan.org
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- CHANGELOG.md
|
104
|
+
- LICENSE.md
|
105
|
+
- README.md
|
106
|
+
- lib/cli-pasta.rb
|
107
|
+
- lib/cli-pasta/epipe.rb
|
108
|
+
- lib/cli-pasta/sigint.rb
|
109
|
+
homepage: https://github.com/chocolateboy/cli-pasta
|
110
|
+
licenses:
|
111
|
+
- Artistic-2.0
|
112
|
+
metadata:
|
113
|
+
bug_tracker_uri: https://github.com/chocolateboy/cli-pasta/issues
|
114
|
+
changelog_uri: https://github.com/chocolateboy/cli-pasta/blob/master/CHANGELOG.md
|
115
|
+
source_code_uri: https://github.com/chocolateboy/cli-pasta
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.7.6
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Handle Ctrl-C and broken-pipe errors gracefully in Ruby command-line tools
|
136
|
+
test_files: []
|