rubyshell 1.2.1 → 1.3.1
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/Rakefile +1 -0
- data/bin/console +11 -0
- data/bin/rubyshell +10 -0
- data/bin/setup +8 -0
- data/lib/rubyshell/chainer.rb +13 -1
- data/lib/rubyshell/command.rb +21 -3
- data/lib/rubyshell/error.rb +14 -0
- data/lib/rubyshell/executor.rb +7 -11
- data/lib/rubyshell/overwrited_commands.rb +17 -0
- data/lib/rubyshell/version.rb +1 -1
- data/lib/rubyshell.rb +2 -0
- metadata +12 -5
- data/exe/rubyshell +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71600c3dfe95d34a08ae287a966739973ec61f50510dab8c40a99bb4bc6941ad
|
|
4
|
+
data.tar.gz: 0b8869b6abd73e47bb9991e7b37d4b8c2a819a7126b506d951c41436449c4df6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5a707cc81ff623438bf32b2bf64c25a29fe2ebad7d6684ffe0900d64b911570553d3c647b9ea967c7c3b23c77a1a59d4db149783519283f3937f2ef2e8e243d
|
|
7
|
+
data.tar.gz: decee58de77cbbbe82586c16f4c3a1b92d4097598c38145eb7ea2b394bd6d2a0c4b7d83681f51d321084c687441e63a98094f552288c5bdbdfb6f93810b75df5
|
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/Rakefile
CHANGED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "rubyshell"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/rubyshell
ADDED
data/bin/setup
ADDED
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,17 @@ 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
|
|
43
|
+
rescue StandardError => e
|
|
44
|
+
raise e if e.is_a?(RubyShell::CommandError)
|
|
45
|
+
|
|
46
|
+
raise RubyShell::CommandError.new(command: to_shell, message: e.message)
|
|
35
47
|
end
|
|
36
48
|
|
|
37
49
|
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,17 @@ module RubyShell
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def exec_command
|
|
16
|
-
|
|
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
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
StringWrapper.new(stdout.chomp)
|
|
24
|
+
end
|
|
25
|
+
rescue StandardError => e
|
|
26
|
+
raise e if e.is_a?(RubyShell::CommandError)
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
raise RubyShell::CommandError.new(command: to_shell, message: e.message)
|
|
21
29
|
end
|
|
22
30
|
|
|
23
31
|
def parsed_args
|
|
@@ -47,4 +55,14 @@ module RubyShell
|
|
|
47
55
|
end.compact
|
|
48
56
|
end
|
|
49
57
|
end
|
|
58
|
+
|
|
59
|
+
class StringWrapper < String
|
|
60
|
+
def inspect
|
|
61
|
+
if $stdin.isatty
|
|
62
|
+
to_s
|
|
63
|
+
else
|
|
64
|
+
super
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
50
68
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyShell
|
|
4
|
+
class CommandError < StandardError
|
|
5
|
+
def initialize(command:, stdout: "", stderr: "", status: "", message: nil)
|
|
6
|
+
@command = command
|
|
7
|
+
@stdout = stdout
|
|
8
|
+
@stderr = stderr
|
|
9
|
+
@status = status
|
|
10
|
+
|
|
11
|
+
super(message || (stderr.empty? ? stdout : stderr))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/rubyshell/executor.rb
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RubyShell
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Dir.chdir(path, &block)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.chain(&block)
|
|
10
|
-
result = RubyShell::ChainContext.class_eval(&block).exec_commands
|
|
4
|
+
module Executor
|
|
5
|
+
module_function
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
include RubyShell::OverwritedCommands
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
def chain(&block)
|
|
10
|
+
RubyShell::ChainContext.class_eval(&block).exec_commands
|
|
15
11
|
end
|
|
16
12
|
|
|
17
|
-
def
|
|
13
|
+
def method_missing(method_name, *args)
|
|
18
14
|
RubyShell::Command.new(method_name, *args).exec_command
|
|
19
15
|
end
|
|
20
16
|
|
|
21
|
-
def
|
|
17
|
+
def respond_to_missing?(_name, _include_private)
|
|
22
18
|
false
|
|
23
19
|
end
|
|
24
20
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyShell
|
|
4
|
+
module OverwritedCommands
|
|
5
|
+
def self.included(mod)
|
|
6
|
+
mod.extend self
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def cd(path, &block)
|
|
10
|
+
Dir.chdir(path, &block)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def ls(*args)
|
|
14
|
+
method_missing(:ls, *args)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/rubyshell/version.rb
CHANGED
data/lib/rubyshell.rb
CHANGED
|
@@ -4,7 +4,9 @@ require_relative "rubyshell/version"
|
|
|
4
4
|
require_relative "rubyshell/command"
|
|
5
5
|
require_relative "rubyshell/chainer"
|
|
6
6
|
require_relative "rubyshell/chain_context"
|
|
7
|
+
require_relative "rubyshell/overwrited_commands"
|
|
7
8
|
require_relative "rubyshell/executor"
|
|
9
|
+
require_relative "rubyshell/error"
|
|
8
10
|
|
|
9
11
|
module Kernel
|
|
10
12
|
def sh(&block)
|
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- albertalef
|
|
8
|
-
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-01-19 00:00:00.000000000 Z
|
|
11
12
|
dependencies: []
|
|
12
13
|
description: A rubist way to run shell commands
|
|
13
14
|
email:
|
|
@@ -20,12 +21,16 @@ files:
|
|
|
20
21
|
- CHANGELOG.md
|
|
21
22
|
- README.md
|
|
22
23
|
- Rakefile
|
|
23
|
-
-
|
|
24
|
+
- bin/console
|
|
25
|
+
- bin/rubyshell
|
|
26
|
+
- bin/setup
|
|
24
27
|
- lib/rubyshell.rb
|
|
25
28
|
- lib/rubyshell/chain_context.rb
|
|
26
29
|
- lib/rubyshell/chainer.rb
|
|
27
30
|
- lib/rubyshell/command.rb
|
|
31
|
+
- lib/rubyshell/error.rb
|
|
28
32
|
- lib/rubyshell/executor.rb
|
|
33
|
+
- lib/rubyshell/overwrited_commands.rb
|
|
29
34
|
- lib/rubyshell/version.rb
|
|
30
35
|
homepage: https://github.com/albertalef/rubyshell
|
|
31
36
|
licenses:
|
|
@@ -36,6 +41,7 @@ metadata:
|
|
|
36
41
|
source_code_uri: https://github.com/albertalef/rubyshell
|
|
37
42
|
changelog_uri: https://github.com/albertalef/rubyshell
|
|
38
43
|
rubygems_mfa_required: 'true'
|
|
44
|
+
post_install_message:
|
|
39
45
|
rdoc_options: []
|
|
40
46
|
require_paths:
|
|
41
47
|
- lib
|
|
@@ -50,7 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
50
56
|
- !ruby/object:Gem::Version
|
|
51
57
|
version: '0'
|
|
52
58
|
requirements: []
|
|
53
|
-
rubygems_version: 3.
|
|
59
|
+
rubygems_version: 3.4.19
|
|
60
|
+
signing_key:
|
|
54
61
|
specification_version: 4
|
|
55
62
|
summary: A rubist way to run shell commands
|
|
56
63
|
test_files: []
|