kommando 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad02b337baae47add97d347389dfb74a7f77f794
4
- data.tar.gz: 6692437c93abe58b1d9ef03055f1d26c880faa59
3
+ metadata.gz: 60fcbc413614b3241e6a3f821c4d906b9c3dde0c
4
+ data.tar.gz: 1dcd5140f6d593f798d7b1fad08f91ca73c4bbbb
5
5
  SHA512:
6
- metadata.gz: 45749321af3f7b74f59ea0e93bbe55de6ee6585ce3abd43c24c4ae8534e2b7eb639caa960dccfdae043e7c1f685f076705928daefa15b601a4b53dc1aad307ba
7
- data.tar.gz: f5cc053fb89f6b5da92694561d4802ff14a6cd6281d205e7fce1e7a43b906f28d589231c910b9e2f8a3c7d62e9df8d0fede5165bc40abba48de8846b496ff6cd
6
+ metadata.gz: e19c3f5ceeef34e4cc387f2eaa434ee92a8a4fc30c58af62338f0aefa6c84fabdee3aaf413bf1b460ffb51c7d39cd9f17b02724c7b7e18cd3336a484b4339b2e
7
+ data.tar.gz: 40d62317bb523c2b8dd29dd5f2f9cb8f3b892cdf36df42e885636cbb08dfb349835a6e5fe760ff94809cd5d7e574ae1444aab6cc710efde91ef3823599020297
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0.2
4
+ Actually useful intial release.
5
+
6
+ - FEAT: Runs commands with arguments `Kommando.new "ping -c 1 google.com"`
7
+ - FEAT: Captures error code in `k.code`
8
+ - EXAMPLES: `ping` and `exit` added.
9
+
10
+ ## 0.0.1
11
+
12
+ Initial release.
13
+
14
+ - FEAT: Runs command without arguments.
15
+ - FEAT: Records the standard out in `k.out`
16
+ - EXAMPLES: `uptime`
data/README.md CHANGED
@@ -24,7 +24,9 @@ TODO: Write usage instructions here
24
24
 
25
25
  ## Development
26
26
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the specs. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ `bin/e2e` runs all Kommando files in `examples/` with `kommando`.
28
30
 
29
31
  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).
30
32
 
data/bin/e2e ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/kommando"
4
+
5
+ find_examples = Kommando.new "find examples -type f -name *"
6
+ find_examples.run
7
+
8
+ for example in find_examples.out.split("\r\n") do
9
+ print "Running #{example} ".ljust(74, ".")
10
+ example = Kommando.new "ruby #{example}"
11
+ example.run
12
+
13
+ raise "Example #{example} did not exit cleanly" unless example.code == 0
14
+
15
+ puts " done"
16
+ end
17
+
18
+ puts ""
19
+ puts "all good."
20
+ exit 0
data/bin/reinstall ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env sh
2
+
3
+ VERSION=$(ruby -r "./lib/kommando/version" -e "puts Kommando::VERSION")
4
+
5
+ gem uninstall kommando
6
+ gem build kommando.gemspec
7
+ gem install kommando-$VERSION.gem
data/examples/exit.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "./lib/kommando"
2
+
3
+ failure = Kommando.new "false"
4
+ failure.run
5
+
6
+ puts "Failure error: #{failure.code}"
7
+
8
+ success = Kommando.new "true"
9
+ success.run
10
+
11
+ puts "Success error: #{success.code}"
data/examples/ping.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.new "ping -c 3 google.com"
4
+ k.run
5
+
6
+ puts k.out
@@ -0,0 +1,6 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.new "uptime"
4
+ k.run
5
+
6
+ puts k.out
data/kommando.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.11"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "rspec-autotest", "~> 1.0"
26
+ spec.add_development_dependency "ZenTest", "~> 4.11"
25
27
  end
data/lib/kommando.rb CHANGED
@@ -1,5 +1,49 @@
1
- require "kommando/version"
1
+ require "pty"
2
2
 
3
- module Kommando
4
- # Your code goes here...
3
+ require_relative "kommando/error"
4
+ require_relative "kommando/version"
5
+ require_relative "kommando/buffer"
6
+
7
+ class Kommando
8
+
9
+ def initialize(cmd)
10
+ @cmd = cmd
11
+ @stdout = Buffer.new
12
+ end
13
+
14
+ def run
15
+ command, *args = @cmd.split " "
16
+ begin
17
+ PTY.spawn(command, *args) do |stdout, stdin, pid|
18
+ Thread.abort_on_exception = true
19
+
20
+ thread_stdout = Thread.new do
21
+ while true do
22
+ break if stdout.eof?
23
+
24
+ c = stdout.getc
25
+ @stdout.append c if c
26
+ end
27
+ end
28
+ thread_stdout.join
29
+
30
+ # http://stackoverflow.com/a/7263243
31
+ Process.wait(pid)
32
+
33
+ @code = $?.exitstatus
34
+ end
35
+ rescue => ex
36
+ raise Kommando::Error, "Command '#{command}' not found"
37
+ end
38
+
39
+ true
40
+ end
41
+
42
+ def out
43
+ @stdout.to_s
44
+ end
45
+
46
+ def code
47
+ @code
48
+ end
5
49
  end
@@ -0,0 +1,15 @@
1
+ class Kommando::Buffer
2
+
3
+ def initialize
4
+ @buffer = []
5
+ end
6
+
7
+ def append(string)
8
+ @buffer << string
9
+ end
10
+
11
+ def to_s
12
+ @buffer.join ""
13
+ end
14
+
15
+ end
@@ -0,0 +1,4 @@
1
+ class Kommando
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
- module Kommando
2
- VERSION = "0.0.1"
1
+ class Kommando
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-autotest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ZenTest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.11'
55
83
  description: Great for integration testing.
56
84
  email:
57
85
  - matti.paksula@iki.fi
@@ -64,14 +92,22 @@ files:
64
92
  - ".ruby-gemset"
65
93
  - ".ruby-version"
66
94
  - ".travis.yml"
95
+ - CHANGELOG.md
67
96
  - Gemfile
68
97
  - LICENSE.txt
69
98
  - README.md
70
99
  - Rakefile
71
100
  - bin/console
101
+ - bin/e2e
102
+ - bin/reinstall
72
103
  - bin/setup
104
+ - examples/exit.rb
105
+ - examples/ping.rb
106
+ - examples/uptime.rb
73
107
  - kommando.gemspec
74
108
  - lib/kommando.rb
109
+ - lib/kommando/buffer.rb
110
+ - lib/kommando/error.rb
75
111
  - lib/kommando/version.rb
76
112
  homepage: http://github.com/matti/kommando
77
113
  licenses: