rubyshell 1.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e1bbca227330e09a8b8421875dc96c6049c23a1046d87a1a2c754569aaf7216
4
- data.tar.gz: 6c4ee7e7b32ee568415ee62301029f407eeccb549265d3980fd961e6876860a8
3
+ metadata.gz: f21be5da171237ec3217b6dde48055661f29a83dea187022b31fa412412d4057
4
+ data.tar.gz: d4a738f0169a395ed449407eb95a0e78df9d6b827472030977db728900ac055d
5
5
  SHA512:
6
- metadata.gz: 842cb4f6b522f1f91ec7e399f2378f0da3c44a362b41336a26c216dfbe706f4b7815bcabdb82e2ba60bc4a867fce90ad6dc0d407daa3b69088ee759c76276f7b
7
- data.tar.gz: ab43aa943d08855ab501ed9c61f7114d427516aeb36db2d10236a05b7c45d4f54c64e58c3751a3eea97b5d8b3f67c736323d7f8c5e60c34c9fce9f24c8a8254b
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/exe/rubyshell CHANGED
@@ -4,4 +4,5 @@
4
4
  require "rubyshell"
5
5
 
6
6
  require "irb"
7
+
7
8
  IRB.start(__FILE__)
@@ -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
- `#{to_shell}`.chomp
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
@@ -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
- result = `#{to_shell}`.chomp
17
-
18
- raise "Command Failed" unless $?.success?
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
- result
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
@@ -43,8 +49,19 @@ module RubyShell
43
49
  "--#{k}"
44
50
  end
45
51
 
46
- [key, v.is_a?(TrueClass) ? nil : v].compact.join(" ")
52
+ [key, v.is_a?(TrueClass) ? nil : "'#{v}'"].compact.join(" ")
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
@@ -1,24 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyShell
4
- class Executor
5
- def self.cd(path, &block)
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 self.chain(&block)
10
- result = RubyShell::ChainContext.class_eval(&block).exec_commands
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 self.method_missing(method_name, *args)
15
+ def method_missing(method_name, *args)
18
16
  RubyShell::Command.new(method_name, *args).exec_command
19
17
  end
20
18
 
21
- def self.respond_to_missing?(_name, _include_private)
19
+ def respond_to_missing?(_name, _include_private)
22
20
  false
23
21
  end
24
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyShell
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
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.2.0
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: 1980-01-02 00:00:00.000000000 Z
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.7.2
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: []