sxmrb 0.1.1 → 0.2.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/.gitlab-ci.yml +4 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +12 -0
- data/README.md +15 -0
- data/lib/sxmrb.rb +21 -42
- data/lib/sxmrb/version.rb +1 -1
- data/sxmrb.gemspec +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4370ef087e7d021313422b6239db2412b76d7c63069d0b60b59730965641191
|
4
|
+
data.tar.gz: 36617e023ae9a845f2ce859856d2b2f863fc3f4caf5c2fbe0ae1822755271f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bf2c8e5536a349c4e72f6f62c009ffa8cfb47796c94074b306d764861e0f20d968055fa877f214eb8b6fab113cba5441508ef93641bae4160f6976d7ae031fd
|
7
|
+
data.tar.gz: acfdfd883bcd28fe6c7aa539f823182e9d004ba7ae19093e7a0133e5cb0a89abd823b740c0f730959a5aaaf117f4253c9a1aaaa7de1f4385806d2c98f0a4215b
|
data/.gitlab-ci.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2021-05-22
|
4
|
+
|
5
|
+
- Wrap "any" standard system commands automatically.
|
6
|
+
|
7
|
+
## [0.1.1] - 2021-05-18
|
8
|
+
|
9
|
+
- Wrap more standard system commands
|
10
|
+
- awk
|
11
|
+
- cat
|
12
|
+
- column
|
13
|
+
- tac
|
14
|
+
|
3
15
|
## [0.1.0] - 2021-05-16
|
4
16
|
|
5
17
|
- Initial release
|
data/README.md
CHANGED
@@ -74,6 +74,21 @@ def input_account
|
|
74
74
|
end
|
75
75
|
```
|
76
76
|
|
77
|
+
### Auto-wrapped system commands
|
78
|
+
|
79
|
+
Missing methods will automatically be wrap corresponding system commands:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Sxmrb.awk('{print $NF}')
|
83
|
+
# => sh('awk', '{print $NF}')
|
84
|
+
|
85
|
+
Sxmrb.column('-t', '-R2')
|
86
|
+
# => sh('column', '-t', '-R2')
|
87
|
+
|
88
|
+
Sxmrb.echo('Hello World')
|
89
|
+
# => sh('echo', 'Hello World')
|
90
|
+
```
|
91
|
+
|
77
92
|
## Development
|
78
93
|
|
79
94
|
After checking out the repo, run `bin/setup` to install
|
data/lib/sxmrb.rb
CHANGED
@@ -8,9 +8,20 @@ require 'shellwords'
|
|
8
8
|
require 'singleton'
|
9
9
|
require 'forwardable'
|
10
10
|
|
11
|
+
begin
|
12
|
+
require 'backports/3.0.0/symbol'
|
13
|
+
rescue LoadError
|
14
|
+
unless Symbol.method_defined? :name
|
15
|
+
# Symbol#name hack
|
16
|
+
class Symbol
|
17
|
+
alias name to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
# SXMO user scripts in ruby.
|
12
23
|
class Sxmrb
|
13
|
-
include Singleton
|
24
|
+
include ::Singleton
|
14
25
|
|
15
26
|
# Normally when using Singleton there is no way to pass arguments
|
16
27
|
# when instantiating. The renew hack below allows the singleton
|
@@ -49,46 +60,6 @@ class Sxmrb
|
|
49
60
|
}
|
50
61
|
end
|
51
62
|
|
52
|
-
# Run the awk command.
|
53
|
-
#
|
54
|
-
# @example
|
55
|
-
# print(sh('ls -l') | awk('{print $1}').to_s)
|
56
|
-
def awk(arg = '')
|
57
|
-
sh("awk -e #{Shellwords.escape arg.chomp}")
|
58
|
-
end
|
59
|
-
|
60
|
-
# Run the cat command.
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
# print cat('/etc/passwd').to_s
|
64
|
-
def cat(arg = '')
|
65
|
-
sh("cat #{arg.chomp}")
|
66
|
-
end
|
67
|
-
|
68
|
-
# Run the column command.
|
69
|
-
#
|
70
|
-
# @example
|
71
|
-
# print(sh('ls -l') | column('-t').to_s)
|
72
|
-
def column(arg = '')
|
73
|
-
sh("column #{arg.chomp}")
|
74
|
-
end
|
75
|
-
|
76
|
-
# Run the shell echo command.
|
77
|
-
#
|
78
|
-
# @example
|
79
|
-
# print echo('Hello World').to_s
|
80
|
-
def echo(arg = '')
|
81
|
-
sh("echo #{Shellwords.escape arg.chomp}")
|
82
|
-
end
|
83
|
-
|
84
|
-
# Run the tac command.
|
85
|
-
#
|
86
|
-
# @example
|
87
|
-
# print tac('/etc/passwd').to_s
|
88
|
-
def tac(arg = '')
|
89
|
-
sh("tac #{arg.chomp}")
|
90
|
-
end
|
91
|
-
|
92
63
|
# Use a blank #menu to prompt for a value.
|
93
64
|
#
|
94
65
|
# @example
|
@@ -97,6 +68,14 @@ class Sxmrb
|
|
97
68
|
(echo | menu(prompt: prompt)).to_s.chomp
|
98
69
|
end
|
99
70
|
|
71
|
+
def method_missing(cmd, *args, &_block)
|
72
|
+
sh(*([cmd.name] + args))
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_missing?(cmd, include_private = false)
|
76
|
+
sh('which', cmd.name).empty? ? super : true
|
77
|
+
end
|
78
|
+
|
100
79
|
class <<self
|
101
80
|
# This evil hack experiment is intended to allow swapping out the
|
102
81
|
# Shell instance when testing.
|
@@ -108,7 +87,7 @@ class Sxmrb
|
|
108
87
|
|
109
88
|
# Forward instance methods to the Singleton instance; false here
|
110
89
|
# excludes ancestor methods.
|
111
|
-
extend Forwardable
|
90
|
+
extend ::Forwardable
|
112
91
|
def_delegators :instance, *Sxmrb.instance_methods(false)
|
113
92
|
end
|
114
93
|
|
data/lib/sxmrb/version.rb
CHANGED
data/sxmrb.gemspec
CHANGED
@@ -32,6 +32,11 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_dependency 'shell'
|
33
33
|
spec.add_dependency 'shellwords'
|
34
34
|
|
35
|
+
# backport Symbol#name, but I didn't want to force a hard dependency
|
36
|
+
# here for just one small piece of code; so, the code will try to load
|
37
|
+
# it from the backports gem first and fall back to a simple monkey patch
|
38
|
+
# spec.add_dependency 'backports', '>= 3.19.0'
|
39
|
+
|
35
40
|
# For more information and examples about making a new gem, checkout our
|
36
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
37
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sxmrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank J. Cameron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shell
|