shellb 0.0.1 → 0.0.2
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -7
- data/lib/shellb/shell.rb +28 -17
- data/lib/shellb/version.rb +1 -1
- data/shellb.gemspec +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f3a0166d547f1e9cadca213c3c4966f958d6deaf424cca3e41c7814fac41cf9
|
|
4
|
+
data.tar.gz: 63230d226d8e24acc56416bd12d737082d140ea0a785ddec4d0994365b7b4e0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38be6a731225de410c59815878f1927cade0f3f01af8bc4181930dae66ec352247891c726bef7230f707419e80e3b3d553c0df6986896e42d9d6f8eb5dee14b2
|
|
7
|
+
data.tar.gz: 1e3f462b44ffef6b6340f99c02921429c1449f49ed4a30b0454dddd7cad8b252611bef5d5fec75e66b14dccdf3083bb62a39de990904b206abe8e18073c21930
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project **may some day** to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.0.2] - 2019-12-03
|
|
8
|
+
### Added
|
|
9
|
+
- Shell#attempt will execute a script and ignore errors
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- Shell#check_point now executes scripts
|
|
13
|
+
- Shell#transact no longer allows chaining with other commands
|
|
14
|
+
|
|
7
15
|
## [0.0.1] - 2019-12-02
|
|
8
16
|
### Added
|
|
9
17
|
- Initial version of ShellB
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -69,13 +69,6 @@ shb = ShellB.new
|
|
|
69
69
|
shb.a("--help") | shb.e("last")
|
|
70
70
|
puts shb.to_sh # => a --help | e last
|
|
71
71
|
|
|
72
|
-
# Mix transact and direct methods
|
|
73
|
-
shb = ShellB.new
|
|
74
|
-
shb.a("--help") | shb.transact do
|
|
75
|
-
e("last") > dest.txt
|
|
76
|
-
end
|
|
77
|
-
puts shb.to_sh # => a --help | e last > dest.txt
|
|
78
|
-
|
|
79
72
|
# Run a script
|
|
80
73
|
shb = ShellB.new
|
|
81
74
|
shb.a("--help") | shb.e("last")
|
|
@@ -142,6 +135,18 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
|
142
135
|
|
|
143
136
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
144
137
|
|
|
138
|
+
## Similar Projects
|
|
139
|
+
|
|
140
|
+
As any good programmer, I wrote first and googled later. Here are some other projects that seem very similar to ShellB:
|
|
141
|
+
|
|
142
|
+
- https://github.com/jgoizueta/sys_cmd
|
|
143
|
+
- https://github.com/duncanbeevers/sheller
|
|
144
|
+
- https://github.com/fetlife/scallop
|
|
145
|
+
- https://github.com/quark-zju/easysh
|
|
146
|
+
- https://github.com/eropple/shellator
|
|
147
|
+
- https://github.com/petyosi/shellshot
|
|
148
|
+
- https://github.com/taccon/eksek
|
|
149
|
+
|
|
145
150
|
## Contributing
|
|
146
151
|
|
|
147
152
|
Bug reports and pull requests are welcome on GitHub at https://github.com/aguynamedryan/shellb.
|
data/lib/shellb/shell.rb
CHANGED
|
@@ -19,9 +19,21 @@ module ShellB
|
|
|
19
19
|
@opts = opts
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def transact(&block)
|
|
23
|
-
instance_eval(&block)
|
|
24
|
-
|
|
22
|
+
def transact(opts = {}, &block)
|
|
23
|
+
instance_eval(&block) if block
|
|
24
|
+
check_point(opts) if opts[:execute]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run(opts = {}, &block)
|
|
28
|
+
transact(opts.merge(execute: true), &block)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def run!(opts = {}, &block)
|
|
32
|
+
run(opts.merge(exit_on_errors: true), &block)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def attempt(opts = {}, &block)
|
|
36
|
+
run(opts.merge(ignore_errors: true), &block)
|
|
25
37
|
end
|
|
26
38
|
|
|
27
39
|
def add_command(command)
|
|
@@ -33,10 +45,7 @@ module ShellB
|
|
|
33
45
|
@commands -= [command]
|
|
34
46
|
end
|
|
35
47
|
|
|
36
|
-
def
|
|
37
|
-
if block
|
|
38
|
-
transact(&block)
|
|
39
|
-
end
|
|
48
|
+
def check_point(opts = {})
|
|
40
49
|
script = Tempfile.new("script.sh")
|
|
41
50
|
script.write(to_sh(opts))
|
|
42
51
|
script.close
|
|
@@ -46,13 +55,13 @@ module ShellB
|
|
|
46
55
|
ee.script = File.read(script)
|
|
47
56
|
raise ee
|
|
48
57
|
end
|
|
58
|
+
rescue ShellB::ExecutionError => ee
|
|
59
|
+
raise(ee) unless opts[:ignore_errors]
|
|
49
60
|
ensure
|
|
61
|
+
@commands = []
|
|
50
62
|
script.close!
|
|
51
63
|
end
|
|
52
|
-
|
|
53
|
-
def run!(opts = {}, &block)
|
|
54
|
-
run(opts.merge(exit_on_errors: true), &block)
|
|
55
|
-
end
|
|
64
|
+
alias execute check_point
|
|
56
65
|
|
|
57
66
|
def to_sh(opts = {})
|
|
58
67
|
str = make_preamble(opts)
|
|
@@ -64,9 +73,15 @@ module ShellB
|
|
|
64
73
|
|
|
65
74
|
def decorate_command(command, opts)
|
|
66
75
|
cmd_str = command.to_sh
|
|
67
|
-
|
|
76
|
+
append = if opts[:exit_on_errors]
|
|
77
|
+
"exit $?"
|
|
78
|
+
elsif opts[:ignore_errors]
|
|
79
|
+
"true"
|
|
80
|
+
else
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
68
83
|
cmd_str = wrap_it(cmd_str, "(") unless command.name == "cd"
|
|
69
|
-
|
|
84
|
+
[cmd_str, append].compact.join(" || ")
|
|
70
85
|
end
|
|
71
86
|
|
|
72
87
|
def method_missing(meth, *args)
|
|
@@ -93,10 +108,6 @@ module ShellB
|
|
|
93
108
|
@commander ||= Commander.new(self)
|
|
94
109
|
end
|
|
95
110
|
|
|
96
|
-
def check_point
|
|
97
|
-
#no-op
|
|
98
|
-
end
|
|
99
|
-
|
|
100
111
|
def pretty_print(pp)
|
|
101
112
|
pp.object_group(self) do
|
|
102
113
|
pp.breakable
|
data/lib/shellb/version.rb
CHANGED
data/shellb.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ["aguynamedryan@gmail.com"]
|
|
11
11
|
|
|
12
12
|
spec.summary = %q{Light DSL to generate shell scripts}
|
|
13
|
-
spec.description = %q{
|
|
13
|
+
spec.description = %q{DSL for shell scripts similar to Ruby's Shell class.}
|
|
14
14
|
spec.homepage = "https://github.com/aguynamedryan/shellb"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shellb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Duryea
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-12-
|
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -66,10 +66,7 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '3.0'
|
|
69
|
-
description:
|
|
70
|
-
all IO passes through Ruby. This gem is heavily inspired by the Shell class, but
|
|
71
|
-
instead generates a script that executes in a shell without having Ruby in the mix,
|
|
72
|
-
keeping things fast.
|
|
69
|
+
description: DSL for shell scripts similar to Ruby's Shell class.
|
|
73
70
|
email:
|
|
74
71
|
- aguynamedryan@gmail.com
|
|
75
72
|
executables: []
|