{"id":15357170,"url":"https://github.com/chocolateboy/cli-pasta","last_synced_at":"2025-04-15T06:43:12.439Z","repository":{"id":52441476,"uuid":"127048453","full_name":"chocolateboy/cli-pasta","owner":"chocolateboy","description":"Handle Ctrl-C and broken-pipe errors gracefully in Ruby command-line tools","archived":false,"fork":false,"pushed_at":"2021-04-29T02:17:44.000Z","size":45,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T06:43:05.753Z","etag":null,"topics":["cli","command-line","ctrl-c","epipe","gem","interrupt","pipe","ruby-gem","rubygem","sigint","signal","sigpipe","zero-dependency"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chocolateboy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-27T21:34:29.000Z","updated_at":"2021-11-02T22:20:17.000Z","dependencies_parsed_at":"2022-08-25T22:22:24.897Z","dependency_job_id":null,"html_url":"https://github.com/chocolateboy/cli-pasta","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fcli-pasta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fcli-pasta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fcli-pasta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fcli-pasta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chocolateboy","download_url":"https://codeload.github.com/chocolateboy/cli-pasta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023727,"owners_count":21199958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line","ctrl-c","epipe","gem","interrupt","pipe","ruby-gem","rubygem","sigint","signal","sigpipe","zero-dependency"],"created_at":"2024-10-01T12:33:39.628Z","updated_at":"2025-04-15T06:43:12.425Z","avatar_url":"https://github.com/chocolateboy.png","language":"Ruby","readme":"# cli-pasta\n\n[![Build Status](https://github.com/chocolateboy/cli-pasta/workflows/test/badge.svg)](https://github.com/chocolateboy/cli-pasta/actions?query=workflow%3Atest)\n[![Gem Version](https://img.shields.io/gem/v/cli-pasta.svg)](https://rubygems.org/gems/cli-pasta)\n\n\u003c!-- TOC --\u003e\n\n- [NAME](#name)\n- [INSTALL](#install)\n- [SYNOPSIS](#synopsis)\n- [DESCRIPTION](#description)\n  - [BACKGROUND](#background)\n- [COMPATIBILITY](#compatibility)\n- [VERSION](#version)\n- [SEE ALSO](#see-also)\n- [AUTHOR](#author)\n- [COPYRIGHT AND LICENSE](#copyright-and-license)\n\n\u003c!-- TOC END --\u003e\n\n# NAME\n\ncli-pasta - handle Ctrl-C and broken-pipe errors gracefully in Ruby command-line tools\n\n# INSTALL\n\n```ruby\ngem \"cli-pasta\"\n```\n\n# SYNOPSIS\n\n```ruby\n#!/usr/bin/env ruby\n\nrequire \"cli-pasta\"\nrequire \"optparse\"\n\n# ...\n\nARGF.each do |line|\n  puts process(line)\nend\n```\n\n# DESCRIPTION\n\ncli-pasta packages boilerplate code which is commonly copied 'n' pasted into\nRuby CLI scripts to perform the following tasks:\n\n- set up a `SIGINT` handler to handle \u003ckbd\u003eCtrl-C\u003c/kbd\u003e in the same way as other CLI tools\n- set up a `SIGPIPE` handler to handle broken pipes in the same way as other CLI tools\n\nThese tasks are executed by loading the corresponding files, either separately, e.g.:\n\n```ruby\nrequire \"cli-pasta/sigint\"\nrequire \"cli-pasta/sigpipe\"\n```\n\nOr as a group:\n\n```ruby\nrequire \"cli-pasta\"\n```\n\n## BACKGROUND\n\nBy default, ruby produces an ugly error message when scripts are interrupted by\n\u003ckbd\u003eCtrl-C\u003c/kbd\u003e (`SIGINT`), e.g.:\n\n    $ timeout --signal INT 1 ruby -e sleep\n\nOutput:\n\n    Traceback (most recent call last):\n            1: from -e:1:in `\u003cmain\u003e'\n    -e:1:in `sleep': Interrupt\n\nThe same is true if a process encounters an error when trying to write to a\nbroken pipe (`EPIPE`), e.g.:\n\n    $ ruby -e 'loop { puts \".\" }' | head -n0\n\nOutput:\n\n    Traceback (most recent call last):\n            5: from -e:1:in `\u003cmain\u003e'\n            4: from -e:1:in `loop'\n            3: from -e:1:in `block in \u003cmain\u003e'\n            2: from -e:1:in `puts'\n            1: from -e:1:in `puts'\n    -e:1:in `write': Broken pipe @ io_writev - \u003cSTDOUT\u003e (Errno::EPIPE)\n\nThe snippets provided by this gem install signal handlers which handle these\nerrors in the same way as other CLI tools, e.g.:\n\n    $ timeout --signal INT 1 ruby -r cli-pasta -e sleep\n    # No output\n\n    $ ruby -r cli-pasta -e 'loop { puts \".\" }' | head -n0\n    # No output\n\n# COMPATIBILITY\n\n- [Maintained ruby versions](https://www.ruby-lang.org/en/downloads/branches/)\n\n# VERSION\n\n2.0.1\n\n# SEE ALSO\n\n* [nice-sigint](https://github.com/xiongchiamiov/nice-sigint) - make Ruby handle SIGINTs in a less-ugly manner\n\n# AUTHOR\n\n[chocolateboy](mailto:chocolate@cpan.org)\n\n# COPYRIGHT AND LICENSE\n\nCopyright © 2018-2021 by chocolateboy.\n\nThis is free software; you can redistribute it and/or modify it under the terms\nof the [MIT license](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fcli-pasta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchocolateboy%2Fcli-pasta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fcli-pasta/lists"}