lucie-cmd 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89a6de7cb0c842f5918571d257ac301465ffd637
4
+ data.tar.gz: 7d7cd153192b1a087278a476cdacfca7495c30fb
5
+ SHA512:
6
+ metadata.gz: aa0562d72fdd3fc50260e3992bb7e21f38707475dc1107d84597694fc1c90fda7cb70a887b8980705eb8ef264e0afced8032d3beda642eb33045172f3d25b488
7
+ data.tar.gz: 886291e9a57cef58057299a3d3599f942071f3d0b8cc79240370b3f5ece1d817aeaefdc28dbb82630481b307be15c99d7b5a35fae866e9dbfaf8b62432164b21
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ html/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lucy.gemspec
4
+ gemspec
5
+
6
+ gem "open4", "1.3.0"
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = false
9
+ t.warning = true
10
+ end
11
+ task :default => :test
12
+
13
+ if !ENV["TRAVIS"]
14
+ require 'rdoc/task'
15
+ RDoc::Task.new :doc do |rdoc|
16
+ rdoc.rdoc_dir = '../doc'
17
+ rdoc.options << '-f' << 'sdoc'
18
+ rdoc.rdoc_files.include("lib/*.rb")
19
+ end
20
+ end
@@ -0,0 +1,55 @@
1
+ require 'open4'
2
+
3
+ module Lucie
4
+ module Commands
5
+
6
+ protected
7
+
8
+ def sh(*args)
9
+ @commands_helper ||= CommandsHelper.new
10
+ @commands_helper.sh(*args)
11
+ end
12
+
13
+ def cd(*args)
14
+ @commands_helper ||= CommandsHelper.new
15
+ @commands_helper.pwd = File.join(args)
16
+ end
17
+
18
+ def output
19
+ @commands_helper.output
20
+ end
21
+
22
+ def status
23
+ @commands_helper.status
24
+ end
25
+
26
+ private
27
+
28
+ class CommandsHelper
29
+ attr_accessor :pwd
30
+
31
+ def initialize
32
+ @stderr = $stderr
33
+ @pwd = Dir.pwd
34
+ end
35
+
36
+ def sh(*args)
37
+ command = args.join(" ")
38
+ @pid, @stdin, @stdout, @stderr = Open4::popen4("cd \"#{pwd}\" && #{command}")
39
+ @ignored, @status = Process::waitpid2 @pid
40
+ end
41
+
42
+ def output
43
+ @stdout.read
44
+ end
45
+
46
+ def status
47
+ @status.to_i % 255
48
+ end
49
+
50
+ def pwd=(val)
51
+ @pwd = File.expand_path(val, @pwd)
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/lucie-cmd.rb ADDED
@@ -0,0 +1 @@
1
+ require "lucie-cmd/commands"
data/lucie-cmd.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ version = File.read(File.expand_path('../../version', __FILE__)).strip
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "lucie-cmd"
8
+ s.version = version
9
+ s.authors = ["Nucc"]
10
+ s.email = ["nucc@bteam.hu"]
11
+ s.description = %q{Shell command for Lucie command line utility framework}
12
+ s.summary = %q{Library part of Lucie framework. Use this gem with Lucie if you want to run commands in shell.}
13
+ s.homepage = "http://my.luc.ie"
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rake", "10.0.3"
21
+ s.add_development_dependency "minitest", "4.6"
22
+ s.add_development_dependency "mini_shoulda", "0.4.0"
23
+ s.add_development_dependency "sdoc"
24
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+ require "stringio"
3
+
4
+ class CdTest < MiniTest::Spec
5
+ include Lucie::Commands
6
+
7
+ it "changes directory" do
8
+ cd "/bin"
9
+ sh "pwd"
10
+ assert_equal "/bin\n", output
11
+ end
12
+
13
+ it "changes directory multiple times" do
14
+ cd "/sbin"
15
+ cd "/bin"
16
+ sh "pwd"
17
+ assert_equal "/bin\n", output
18
+ end
19
+
20
+ it "knows relative paths" do
21
+ cd "/bin"
22
+ cd "../sbin"
23
+ sh "pwd"
24
+ assert_equal "/sbin\n", output
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ require "test_helper"
2
+ require "stringio"
3
+
4
+ class ShTest < MiniTest::Spec
5
+ include Lucie::Commands
6
+
7
+ it "runs a command" do
8
+ sh "echo 123"
9
+ assert_equal "123\n", output
10
+ end
11
+
12
+ it "runs more commands" do
13
+ sh "echo 1"
14
+ assert_equal "1\n", output
15
+ sh "echo 2"
16
+ assert_equal "2\n", output
17
+ end
18
+
19
+ it "knows the return status" do
20
+ sh "false"
21
+ assert_equal 1, status
22
+
23
+ sh "true"
24
+ assert_equal 0, status
25
+ end
26
+
27
+ it "can handle return status of concurrent processes" do
28
+ i = 0
29
+ th1 = Thread.new do
30
+ sh "true"
31
+ i = 1
32
+ sleep 0 while i != 2
33
+ assert 0, status
34
+ i = 3
35
+ end
36
+
37
+ th2 = Thread.new do
38
+ sleep 0 while i != 1
39
+ sh "false"
40
+ i = 2
41
+ sleep 0 while i != 3
42
+ assert 1, status
43
+ end
44
+
45
+ th1.join
46
+ th2.join
47
+ end
48
+
49
+ end
@@ -0,0 +1,15 @@
1
+ if ENV["TRAVIS"]
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
6
+ # MiniTest is integrated to Ruby library and by default the test wants to use that.
7
+ # Force the Rubygems version
8
+ require 'minitest/autorun'
9
+ require "mini_shoulda"
10
+ #require 'debugger'
11
+
12
+ require "lucie-cmd"
13
+
14
+ class MiniTest::Spec
15
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lucie-cmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Nucc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 10.0.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 10.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '4.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '4.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mini_shoulda
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Shell command for Lucie command line utility framework
70
+ email:
71
+ - nucc@bteam.hu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - Rakefile
79
+ - lib/lucie-cmd.rb
80
+ - lib/lucie-cmd/commands.rb
81
+ - lucie-cmd.gemspec
82
+ - test/functional/cd_test.rb
83
+ - test/functional/sh_test.rb
84
+ - test/test_helper.rb
85
+ homepage: http://my.luc.ie
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Library part of Lucie framework. Use this gem with Lucie if you want to run
108
+ commands in shell.
109
+ test_files:
110
+ - test/functional/cd_test.rb
111
+ - test/functional/sh_test.rb
112
+ - test/test_helper.rb