omg-thor-ext 0.1.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.
- checksums.yaml +7 -0
- data/README.md +37 -0
- data/lib/thor_ext.rb +51 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6ff852a38ac2fb14b24322624a09954d0f17a83f5033f8a34b4aec053e7bd49
|
4
|
+
data.tar.gz: 7e9502a446a5c984a8af524f10f5c1c415581d921ab55fab7d5367489977dca5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9be6bbd4492860365bfb8bff70e1520a5affc1004cbff0044808f4517e9129c3d2379518b9dd3bafe832e479cc5982234c3529baf733cf4da6760ee23044408
|
7
|
+
data.tar.gz: a4730ed0c378b160668884083ec7d452386ae0b908d66a14fd43cc151c9cb613e2ca231217c0a7ef1dcd2886e855c54dbef279aeaf700880675f7d3ca94c0c56
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Thor extension
|
2
|
+
|
3
|
+
[Matt Brictson](https://github.com/mattbrictson) had the same complaints I did about [Thor](https://github.com/rails/thor). Well, he went and fixed them all, I put them into a gem and now use it in many of my Thor CLIs.
|
4
|
+
|
5
|
+
## Original source
|
6
|
+
|
7
|
+
https://github.com/mattbrictson/gem/blob/main/lib/example/thor_ext.rb
|
8
|
+
|
9
|
+
## What it does
|
10
|
+
|
11
|
+
Overwrites a few Thor methods so that it behaves more like a typical CLI:
|
12
|
+
|
13
|
+
- Accepts `-h` or `--help` to show help
|
14
|
+
- Treats unrecognized options as errors instead of ignoring them
|
15
|
+
- Prints error to `stderr` in red with no stacktrace
|
16
|
+
- Prints full stacktrace when setting `VERBOSE` environment variable
|
17
|
+
- Exists with a non-zero status on error
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem i thor-ext
|
23
|
+
```
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'thor-ext'
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
In your Thor CLI:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class SuperAwesomeCli < Thor
|
35
|
+
extend ThorExt::Start
|
36
|
+
end
|
37
|
+
```
|
data/lib/thor_ext.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module ThorExt
|
6
|
+
VERSION = '0.1.0'
|
7
|
+
|
8
|
+
module Start
|
9
|
+
def self.extended(base)
|
10
|
+
super
|
11
|
+
base.check_unknown_options!
|
12
|
+
end
|
13
|
+
|
14
|
+
def start(given_args = ARGV, config = {})
|
15
|
+
config[:shell] ||= ::Thor::Base.shell.new
|
16
|
+
handle_help_switches(given_args) do |args|
|
17
|
+
dispatch(nil, args, nil, config)
|
18
|
+
end
|
19
|
+
rescue StandardError => e
|
20
|
+
handle_exception_on_start(e, config)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def handle_help_switches(given_args)
|
26
|
+
yield(given_args.dup)
|
27
|
+
rescue ::Thor::UnknownArgumentError => e
|
28
|
+
retry_with_args = []
|
29
|
+
|
30
|
+
if given_args.first == 'help'
|
31
|
+
retry_with_args = ['help'] if given_args.length > 1
|
32
|
+
elsif (e.unknown & %w[-h --help]).any?
|
33
|
+
retry_with_args = ['help', (given_args - e.unknown).first]
|
34
|
+
end
|
35
|
+
raise if retry_with_args.none?
|
36
|
+
|
37
|
+
yield(retry_with_args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def handle_exception_on_start(error, config)
|
41
|
+
return if error.is_a?(Errno::EPIPE)
|
42
|
+
raise if ENV['VERBOSE'] || !config.fetch(:exit_on_failure, true)
|
43
|
+
|
44
|
+
message = error.full_message.to_s
|
45
|
+
message.prepend("[#{error.class}] ") if message.empty? || !error.is_a?(::Thor::Error)
|
46
|
+
|
47
|
+
config[:shell]&.say_error(message, :red)
|
48
|
+
exit(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omg-thor-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Greenfield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Original source: https://github.com/mattbrictson/gem/blob/main/lib/example/thor_ext.rb'
|
14
|
+
email:
|
15
|
+
- mattgreenfield1@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/thor_ext.rb
|
22
|
+
homepage: https://github.com/omgreenfield/thor-ext
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata:
|
26
|
+
homepage_uri: https://github.com/omgreenfield/thor-ext
|
27
|
+
source_code_uri: https://github.com/omgreenfield/thor-ext
|
28
|
+
rubygems_mfa_required: 'true'
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.7.7
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.4.6
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Packages Matt Brictson's extension to make Thor behave like a typical CLI
|
48
|
+
test_files: []
|