rubyshell 1.2.1 → 1.3.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 +4 -4
- data/README.md +20 -0
- data/lib/rubyshell/chainer.rb +9 -1
- data/lib/rubyshell/command.rb +21 -4
- data/lib/rubyshell/executor.rb +8 -10
- data/lib/rubyshell/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f21be5da171237ec3217b6dde48055661f29a83dea187022b31fa412412d4057
|
|
4
|
+
data.tar.gz: d4a738f0169a395ed449407eb95a0e78df9d6b827472030977db728900ac055d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: afe062bedbf8e8f1064aa662c8925364da817279fb83d9a2af74ea552cd146aa63d17fda67b7c16e608a3f0b386d5d0bc1cdcb6365398cc3e726f6255ff33de7
|
|
7
|
+
data.tar.gz: 369ac530ad58e8ed4489ca17536dcf9786491b8a641e04a24c565f8182b6d10b9e043d5714d50969bcd438a8d13e8388ba3a11b0628891d51aff5c01a80014ec
|
data/README.md
CHANGED
|
@@ -65,6 +65,15 @@ sh do
|
|
|
65
65
|
end
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
### Using without the block
|
|
69
|
+
If you want to start an irb or pry session, and run commands as first-class citizens then do the following.
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
extend RubyShell::Executor
|
|
73
|
+
|
|
74
|
+
pwd # => /Users/albertalef/projects/rubyshell
|
|
75
|
+
```
|
|
76
|
+
|
|
68
77
|
### Passing arguments
|
|
69
78
|
Here we have different ways to pass arguments to a command.
|
|
70
79
|
You can separate strings, use only one, use hashes, anyway will work
|
|
@@ -124,6 +133,17 @@ sh do
|
|
|
124
133
|
end
|
|
125
134
|
```
|
|
126
135
|
|
|
136
|
+
### Executing without a block
|
|
137
|
+
The `sh` method can receive any method call, and execute shell commands
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
sh.puts pwd # => /Users/albertalef/projects/rubyshell
|
|
141
|
+
|
|
142
|
+
sh.cd 'examples'
|
|
143
|
+
|
|
144
|
+
puts sh.pwd # => /Users/albertalef/projects/rubyshell/examples
|
|
145
|
+
```
|
|
146
|
+
|
|
127
147
|
## Complete example
|
|
128
148
|
|
|
129
149
|
```ruby
|
data/lib/rubyshell/chainer.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
3
5
|
module RubyShell
|
|
4
6
|
class Chainer
|
|
5
7
|
attr_reader :parts
|
|
@@ -31,7 +33,13 @@ module RubyShell
|
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def exec_commands
|
|
34
|
-
|
|
36
|
+
Open3.capture3(to_shell).then do |stdout, stderr, status|
|
|
37
|
+
unless status.success?
|
|
38
|
+
raise RubyShell::CommandError.new(command: to_shell, stdout: stdout, stderr: stderr, status: status)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
stdout.chomp
|
|
42
|
+
end
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
def to_shell
|
data/lib/rubyshell/command.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
3
5
|
module RubyShell
|
|
4
6
|
class Command
|
|
5
7
|
def initialize(command_name, *args, &block)
|
|
@@ -13,11 +15,15 @@ module RubyShell
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def exec_command
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
Open3.capture3(to_shell).then do |stdout, stderr, status|
|
|
19
|
+
unless status.success?
|
|
20
|
+
raise RubyShell::CommandError.new(command: to_shell, stdout: stdout, stderr: stderr, status: status)
|
|
21
|
+
end
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
stdout.chomp
|
|
24
|
+
end
|
|
25
|
+
rescue StandardError
|
|
26
|
+
raise RubyShell::CommandError.new(command: to_shell)
|
|
21
27
|
end
|
|
22
28
|
|
|
23
29
|
def parsed_args
|
|
@@ -47,4 +53,15 @@ module RubyShell
|
|
|
47
53
|
end.compact
|
|
48
54
|
end
|
|
49
55
|
end
|
|
56
|
+
|
|
57
|
+
class CommandError < StandardError
|
|
58
|
+
def initialize(command:, stdout: "", stderr: "", status: "")
|
|
59
|
+
@command = command
|
|
60
|
+
@stdout = stdout
|
|
61
|
+
@stderr = stderr
|
|
62
|
+
@status = status
|
|
63
|
+
|
|
64
|
+
super
|
|
65
|
+
end
|
|
66
|
+
end
|
|
50
67
|
end
|
data/lib/rubyshell/executor.rb
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RubyShell
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module Executor
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
def cd(path, &block)
|
|
6
8
|
Dir.chdir(path, &block)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
raise "Command Failed" unless $?.success?
|
|
13
|
-
|
|
14
|
-
result
|
|
11
|
+
def chain(&block)
|
|
12
|
+
RubyShell::ChainContext.class_eval(&block).exec_commands
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
def
|
|
15
|
+
def method_missing(method_name, *args)
|
|
18
16
|
RubyShell::Command.new(method_name, *args).exec_command
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
def
|
|
19
|
+
def respond_to_missing?(_name, _include_private)
|
|
22
20
|
false
|
|
23
21
|
end
|
|
24
22
|
end
|
data/lib/rubyshell/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubyshell
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- albertalef
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-01-18 00:00:00.000000000 Z
|
|
11
12
|
dependencies: []
|
|
12
13
|
description: A rubist way to run shell commands
|
|
13
14
|
email:
|
|
@@ -36,6 +37,7 @@ metadata:
|
|
|
36
37
|
source_code_uri: https://github.com/albertalef/rubyshell
|
|
37
38
|
changelog_uri: https://github.com/albertalef/rubyshell
|
|
38
39
|
rubygems_mfa_required: 'true'
|
|
40
|
+
post_install_message:
|
|
39
41
|
rdoc_options: []
|
|
40
42
|
require_paths:
|
|
41
43
|
- lib
|
|
@@ -50,7 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
50
52
|
- !ruby/object:Gem::Version
|
|
51
53
|
version: '0'
|
|
52
54
|
requirements: []
|
|
53
|
-
rubygems_version: 3.
|
|
55
|
+
rubygems_version: 3.4.19
|
|
56
|
+
signing_key:
|
|
54
57
|
specification_version: 4
|
|
55
58
|
summary: A rubist way to run shell commands
|
|
56
59
|
test_files: []
|