samovar 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/samovar.rb +19 -0
- data/lib/samovar/command.rb +5 -2
- data/lib/samovar/command/system.rb +60 -0
- data/lib/samovar/command/track_time.rb +37 -0
- data/lib/samovar/many.rb +1 -1
- data/lib/samovar/output.rb +1 -1
- data/lib/samovar/table.rb +1 -1
- data/lib/samovar/version.rb +21 -1
- data/spec/{samovar_spec.rb → samovar/command_spec.rb} +9 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 245b832e19301eafe975c8bc751f3d8f7c5f5fab
|
4
|
+
data.tar.gz: 8db97750516f551f87c9d614958e53e191a0d665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a57f9f297cf8c2b77e7d49185991dc154bb7dc0968a0c220ea666d84306bb10a6fc07f8ece5593b3776deae3f356ed857475ac314dfc1fa5b5aea616e7c64ee
|
7
|
+
data.tar.gz: a76705582cda894101104c34d73ab0c7dcec1b15557302c5ed753fce3746ccacc27de7151a29855351abcb0411406f841c84244fd53ad322320e532e6f446a31
|
data/README.md
CHANGED
@@ -30,7 +30,11 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
The best example of a working Samovar command line is probably [Teapot](https://github.com/ioquatix/teapot/blob/master/lib/teapot/command.rb).
|
33
|
+
The best example of a working Samovar command line is probably [Teapot](https://github.com/ioquatix/teapot/blob/master/lib/teapot/command.rb).
|
34
|
+
|
35
|
+
[Utopia](https://github.com/ioquatix/utopia/blob/master/lib/utopia/command.rb) shows how to use multiple levels of nested commands.
|
36
|
+
|
37
|
+
Please feel free to submit other examples and I will link to them here.
|
34
38
|
|
35
39
|
## Contributing
|
36
40
|
|
data/lib/samovar.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
require_relative 'samovar/version'
|
3
22
|
require_relative 'samovar/command'
|
data/lib/samovar/command.rb
CHANGED
@@ -27,6 +27,9 @@ require_relative 'split'
|
|
27
27
|
|
28
28
|
require_relative 'output'
|
29
29
|
|
30
|
+
require_relative 'command/system'
|
31
|
+
require_relative 'command/track_time'
|
32
|
+
|
30
33
|
module Samovar
|
31
34
|
class IncompleteParse < StandardError
|
32
35
|
end
|
@@ -40,10 +43,10 @@ module Samovar
|
|
40
43
|
return command
|
41
44
|
end
|
42
45
|
|
43
|
-
def initialize(input)
|
46
|
+
def initialize(input = nil)
|
44
47
|
self.class.table.parse(input) do |key, value|
|
45
48
|
self.send("#{key}=", value)
|
46
|
-
end
|
49
|
+
end if input
|
47
50
|
end
|
48
51
|
|
49
52
|
def [] key
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'time'
|
22
|
+
|
23
|
+
module Samovar
|
24
|
+
class SystemError < RuntimeError
|
25
|
+
end
|
26
|
+
|
27
|
+
class Command
|
28
|
+
def system(*args, **options)
|
29
|
+
command_line = args.join(' ')
|
30
|
+
|
31
|
+
pid = Process.spawn(*args, **options)
|
32
|
+
|
33
|
+
puts Rainbow(command_line).color(:blue)
|
34
|
+
|
35
|
+
status = Process.waitpid2(pid).last
|
36
|
+
|
37
|
+
return status.success?
|
38
|
+
rescue Errno::ENOENT
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
def system!(*args, **options)
|
43
|
+
command_line = args.join(' ')
|
44
|
+
|
45
|
+
pid = Process.spawn(*args, **options)
|
46
|
+
|
47
|
+
puts Rainbow(command_line).color(:blue)
|
48
|
+
|
49
|
+
status = Process.waitpid2(pid).last
|
50
|
+
|
51
|
+
if status.success?
|
52
|
+
return true
|
53
|
+
else
|
54
|
+
raise SystemError.new("Command #{command_line.dump} failed: #{status.to_s}")
|
55
|
+
end
|
56
|
+
rescue Errno::ENOENT
|
57
|
+
raise SystemError.new("Command #{command_line.dump} failed: #{$!}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'time'
|
22
|
+
|
23
|
+
module Samovar
|
24
|
+
class Command
|
25
|
+
def track_time
|
26
|
+
start_time = Time.now
|
27
|
+
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
end_time = Time.now
|
31
|
+
elapsed_time = end_time - start_time
|
32
|
+
|
33
|
+
$stdout.flush
|
34
|
+
$stderr.puts Rainbow("Elapsed Time: %0.3fs" % elapsed_time).magenta
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/samovar/many.rb
CHANGED
data/lib/samovar/output.rb
CHANGED
data/lib/samovar/table.rb
CHANGED
data/lib/samovar/version.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
1
21
|
module Samovar
|
2
|
-
|
22
|
+
VERSION = "1.1.0"
|
3
23
|
end
|
@@ -27,7 +27,7 @@ module Command
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe Samovar do
|
30
|
+
describe Samovar::Command do
|
31
31
|
it "should parse a simple command" do
|
32
32
|
top = Command::Top.parse(["-c", "path", "bottom", "foobar", "A", "B", "--", "args", "args"])
|
33
33
|
|
@@ -45,4 +45,12 @@ describe Samovar do
|
|
45
45
|
|
46
46
|
expect(buffer.string).to be_include(Command::Top.description)
|
47
47
|
end
|
48
|
+
|
49
|
+
it "can run commands" do
|
50
|
+
expect(subject.system("ls")).to be_truthy
|
51
|
+
expect(subject.system!("ls")).to be_truthy
|
52
|
+
|
53
|
+
expect(subject.system("fail")).to be_falsey
|
54
|
+
expect{subject.system!("fail")}.to raise_error(Samovar::SystemError)
|
55
|
+
end
|
48
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samovar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mapping
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- flopp.gemspec
|
98
98
|
- lib/samovar.rb
|
99
99
|
- lib/samovar/command.rb
|
100
|
+
- lib/samovar/command/system.rb
|
101
|
+
- lib/samovar/command/track_time.rb
|
100
102
|
- lib/samovar/flags.rb
|
101
103
|
- lib/samovar/many.rb
|
102
104
|
- lib/samovar/nested.rb
|
@@ -107,7 +109,7 @@ files:
|
|
107
109
|
- lib/samovar/split.rb
|
108
110
|
- lib/samovar/table.rb
|
109
111
|
- lib/samovar/version.rb
|
110
|
-
- spec/
|
112
|
+
- spec/samovar/command_spec.rb
|
111
113
|
- teapot.png
|
112
114
|
homepage: https://github.com/ioquatix/samovar
|
113
115
|
licenses:
|
@@ -135,4 +137,4 @@ specification_version: 4
|
|
135
137
|
summary: Samovar is a flexible option parser excellent support for sub-commands and
|
136
138
|
help documentation.
|
137
139
|
test_files:
|
138
|
-
- spec/
|
140
|
+
- spec/samovar/command_spec.rb
|