shelltastic 0.4.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: 9b07dd350e166ed03ad713679d70d7ea6240e187
4
- data.tar.gz: 210773d437ad75e55344586d6ad7e2c17664c02d
2
+ SHA256:
3
+ metadata.gz: 89419f6c9c35e7a71c2e181f12baa3999c7722e93908952008730c106ede5ca6
4
+ data.tar.gz: e1a6101fb87f0f06f1d09d605d9554342f081a57c186ef6432a1a042f748e054
5
5
  SHA512:
6
- metadata.gz: a80dcb34fcfc4cef75f0f7f74f0361714d84059eaf95791e832a6e8d275fd463e5f1b764ba32bd8d567daabfedd39775f5fe60ab6be0d2fee3c2d04f7c3a355d
7
- data.tar.gz: 398974008814c3d93bb2ae2478dbcfed6064b948e8f96ccaaa5d7be8a59b01aa284437e5db75ef265092ba2141bd8eef865c58860df2e3791f7b6fcaf71312f7
6
+ metadata.gz: 1398fe39bca978e54368015448baa52ae6807d68533142180a07021a40ed3f67ee1a42694dd4e32a0741b903ba85dcd4b90af661fa6efb2006fd07228bd83e8c
7
+ data.tar.gz: 8356a89b04eb97814b99711b13fb2b802c64e2af205cdccf5cbb820e464b03ec1f6a803598823e402fa51dfe1253b7f39df7e5b90c6c1f986602bc4a885f7085
data/README.md CHANGED
@@ -17,6 +17,8 @@ Or install it yourself as:
17
17
 
18
18
  ## Usage
19
19
 
20
+ ### Run
21
+
20
22
  ```ruby
21
23
  ShellTastic::Command.run("date")
22
24
  ```
@@ -30,7 +32,18 @@ The above will return an Array of hash meta-data.
30
32
  For example, the above command's return would look something like this:
31
33
 
32
34
  ```ruby
33
- [{:output=>"Sun Feb 3 17:41:45 EST 2013", :pid=>17507, :error=>false, :start=>2013-02-03 17:41:45 -0500, :stop=>2013-02-03 17:41:45 -0500, :total_time=>0.004405272, :exitstatus=>0}]
35
+ [
36
+ {
37
+ :output=>"Sun Feb 3 17:41:45 EST 2013",
38
+ :pid=>17507,
39
+ :command => "date",
40
+ :error=>false,
41
+ :start=>2013-02-03 17:41:45 -0500,
42
+ :stop=>2013-02-03 17:41:45 -0500,
43
+ :total_time=>0.004405272,
44
+ :exitstatus=>0
45
+ }
46
+ ]
34
47
  ```
35
48
 
36
49
  You can also pass multiple commands separated by commas or pass an array.
@@ -44,7 +57,74 @@ ShellTastic::Command.run(["date", "whoami"])
44
57
  ```
45
58
 
46
59
  ```ruby
47
- [{:output=>"Sat Apr 6 15:26:05 EDT 2013", :pid=>92558, :error=>false, :start=>2013-04-06 15:26:05 -0400, :stop=>2013-04-06 15:26:05 -0400, :command=>"date", :total_time=>0.010004, :exitstatus=>0}, {:output=>"bradleydsmith", :pid=>92559, :error=>false, :start=>2013-04-06 15:26:05 -0400, :stop=>2013-04-06 15:26:05 -0400, :command=>"whoami", :total_time=>0.008262, :exitstatus=>0}]
60
+ [
61
+ {
62
+ :output=>"Sat Apr 6 15:26:05 EDT 2013",
63
+ :pid=>92558,
64
+ :error=>false,
65
+ :start=>2013-04-06 15:26:05 -0400,
66
+ :stop=>2013-04-06 15:26:05 -0400,
67
+ :command=>"date",
68
+ :total_time=>0.010004,
69
+ :exitstatus=>0
70
+ },
71
+
72
+ {
73
+ :output=>"bradleydsmith",
74
+ :pid=>92559,
75
+ :error=>false,
76
+ :start=>2013-04-06 15:26:05 -0400,
77
+ :stop=>2013-04-06 15:26:05 -0400,
78
+ :command=>"whoami",
79
+ :total_time=>0.008262,
80
+ :exitstatus=>0
81
+ }
82
+ ]
83
+ ```
84
+
85
+ ### Start
86
+ Start will run a command in the background and return the pid immediately.
87
+
88
+ It takes the same command arguments as `#run`
89
+
90
+ The parent process (you) will not wait for the child to finish or return any information.
91
+
92
+ This is useful if you want to run a command, but dont care about the output or exit status.
93
+
94
+ __BEWARE__ of long running commands that could fail. ShellTastic detaches itself from the child command.
95
+
96
+
97
+
98
+ ```ruby
99
+ ShellTastic::Command.start("sleep 10; date")
100
+ ```
101
+ or
102
+
103
+ ```ruby
104
+ ShellTastic::Command.start(["sleep 10", "date"])
105
+ ```
106
+
107
+ The above will return an Array of hash meta-data.
108
+
109
+ ```ruby
110
+ [{ :output, :pid, :error, :start, :stop, :total_time, :exitstatus, :command }]
111
+ ```
112
+
113
+ For example, the above command's return would look something like this:
114
+
115
+ ```ruby
116
+ [
117
+ {
118
+ :output=>nil,
119
+ :pid=>17507,
120
+ :error=>false,
121
+ :start=>2013-02-03 17:41:45 -0500,
122
+ :stop=>2013-02-03 17:41:45 -0500,
123
+ :command=>"sleep 10; date",
124
+ :total_time=>0.004405272,
125
+ :exitstatus=>nil
126
+ }
127
+ ]
48
128
  ```
49
129
 
50
130
 
data/lib/shelltastic.rb CHANGED
@@ -20,6 +20,10 @@ module ShellTastic
20
20
  def run(*command)
21
21
  command.flatten.map { |cmd| ShellTastic::IO.popen(cmd, ShellTastic::Timer.new, ShellTastic::OutputFormatter.new) }
22
22
  end
23
+
24
+ def start(*command)
25
+ command.flatten.map { |cmd| ShellTastic::IO.fire_and_forget(cmd, ShellTastic::Timer.new, ShellTastic::OutputFormatter.new) }
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -37,6 +37,40 @@ module ShellTastic
37
37
  end
38
38
  formatter.inspect
39
39
  end
40
+
41
+ # run command in background dont wait for it to exit
42
+ #
43
+ # @see #start
44
+ # @param command [String] command(s) to execute
45
+ # @param command [Time] time object for run time
46
+ # @param command [Formatter] formatter object to build output
47
+ # @return [Hash] hash meta-data for the command executed
48
+ # @note output, error , exitstatus will be nil
49
+ # @example
50
+ # { :output, :pid, :error, :start, :stop, :total_time, :exitstatus }
51
+ def fire_and_forget(command, timer, formatter)
52
+ string_nil_or_blank! command
53
+ begin
54
+ formatter.start = timer.start
55
+ pid = Process.spawn(command, :pgroup=>true, [:out, :err, :in] => "/dev/null")
56
+ formatter.build(command: command,
57
+ output: nil,
58
+ pid: pid,
59
+ error: false,
60
+ stop: timer.stop,
61
+ exitstatus: $?,
62
+ total_time: timer.total_time)
63
+
64
+ Process.detach(pid)
65
+ formatter.inspect
66
+ rescue Errno::ENOENT => e
67
+ Process.kill(9, pid) if pid
68
+ raise ShellTastic::CommandException.new("Shell command #{command} failed with status #{$?} and ERROR: #{e.message}")
69
+ ensure
70
+ Process.detach(pid) if pid
71
+ end
72
+ end
73
+
40
74
  end
41
75
  end
42
76
  end
@@ -1,3 +1,3 @@
1
1
  module ShellTastic
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/shelltastic.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.version = ShellTastic::VERSION
9
9
  gem.authors = ["Bradley Smith"]
10
10
  gem.email = ["bradleydsmith@gmail.com"]
11
- gem.description = %q{Shelltastic is a simple *nix shell wrapper}
12
- gem.summary = %q{Shelltastic is a simple *nix shell wrapper}
13
- gem.homepage = ""
11
+ gem.description = %q{Shelltastic is a simple *nix shell wrapper that you can use in your own applications.}
12
+ gem.summary = %q{Shelltastic is a simple *nix shell wrapper.}
13
+ gem.homepage = "https://github.com/bradleyd/shelltastic"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -39,5 +39,27 @@ describe ShellTastic do
39
39
  result[:error].should_not eq(false)
40
40
  end
41
41
 
42
+ # fire and forget
43
+ it "should fire a command in the background and have a pid" do
44
+ result = ShellTastic::Command.start("ls -al /").first
45
+ result[:pid].should_not be_nil
46
+ end
47
+
48
+ it "should fire a command in the background and have a command" do
49
+ result = ShellTastic::Command.start("ls -al /").first
50
+ result[:command].should eq("ls -al /")
51
+ end
52
+
53
+ it "should fire a command in the background and have no ouput" do
54
+ result = ShellTastic::Command.start("ls -al /").first
55
+ result[:output].should be_nil
56
+ end
57
+
58
+ it "should fire a command in the background and not raise an error" do
59
+ expect {
60
+ ShellTastic::Command.start("foobar").first
61
+ }.to raise_error(ShellTastic::CommandException)
62
+ end
63
+
42
64
 
43
65
  end
metadata CHANGED
@@ -1,66 +1,67 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelltastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Smith
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open4
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Shelltastic is a simple *nix shell wrapper
55
+ description: Shelltastic is a simple *nix shell wrapper that you can use in your own
56
+ applications.
56
57
  email:
57
58
  - bradleydsmith@gmail.com
58
59
  executables: []
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
62
- - .gitignore
63
- - .rspec
63
+ - ".gitignore"
64
+ - ".rspec"
64
65
  - CHANGELOG.md
65
66
  - Gemfile
66
67
  - LICENSE.txt
@@ -79,29 +80,28 @@ files:
79
80
  - spec/spec_helper.rb
80
81
  - spec/timer_spec.rb
81
82
  - tags
82
- homepage: ''
83
+ homepage: https://github.com/bradleyd/shelltastic
83
84
  licenses: []
84
85
  metadata: {}
85
- post_install_message:
86
+ post_install_message:
86
87
  rdoc_options: []
87
88
  require_paths:
88
89
  - lib
89
90
  required_ruby_version: !ruby/object:Gem::Requirement
90
91
  requirements:
91
- - - '>='
92
+ - - ">="
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  requirements:
96
- - - '>='
97
+ - - ">="
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.1.11
102
- signing_key:
101
+ rubygems_version: 3.2.22
102
+ signing_key:
103
103
  specification_version: 4
104
- summary: Shelltastic is a simple *nix shell wrapper
104
+ summary: Shelltastic is a simple *nix shell wrapper.
105
105
  test_files:
106
106
  - spec/output_formatter_spec.rb
107
107
  - spec/shelltastic_spec.rb