shelltastic 0.4.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9b07dd350e166ed03ad713679d70d7ea6240e187
4
- data.tar.gz: 210773d437ad75e55344586d6ad7e2c17664c02d
2
+ SHA256:
3
+ metadata.gz: 20dc0136766aee9463af6c60624299cf3501267df0eb529b4b0f609434aeb9a2
4
+ data.tar.gz: b1daff36ac9f708334715dad20aab079ed2ca43bea163c820373639342cf1142
5
5
  SHA512:
6
- metadata.gz: a80dcb34fcfc4cef75f0f7f74f0361714d84059eaf95791e832a6e8d275fd463e5f1b764ba32bd8d567daabfedd39775f5fe60ab6be0d2fee3c2d04f7c3a355d
7
- data.tar.gz: 398974008814c3d93bb2ae2478dbcfed6064b948e8f96ccaaa5d7be8a59b01aa284437e5db75ef265092ba2141bd8eef865c58860df2e3791f7b6fcaf71312f7
6
+ metadata.gz: fbb7ebf36c4682cb9062ed86a04a033bc7d46a2ed87382ac9d3999573539228c5f5159327601731114423e0d5abeb0cdb24a54e725ada965372036a845ee2348
7
+ data.tar.gz: 307c95d92238bb2776dec664b4a6be2335541787d172cfa63334fe18181f3cb3a0291234d4d562766825586b33540160390cc79e504ac9069c7932746f785ee4
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.6', '2.7', '3.0']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .tool-versions
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+ * Added `start` command to run commands in the background. Bump Version 0.5.0
5
+
3
6
  ## 0.4.0
4
7
  * `:error` returns false now if there is not an error--instead of empty string
5
8
 
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Shelltastic
2
2
  Shelltastic is simple *nix shell wrapper for ruby. You can pass a single command or multiple commands to run.
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/shelltastic.svg)](https://badge.fury.io/rb/shelltastic)
5
+
6
+
4
7
  ## Installation
5
8
 
6
9
  Add this line to your application's Gemfile:
@@ -17,6 +20,8 @@ Or install it yourself as:
17
20
 
18
21
  ## Usage
19
22
 
23
+ ### Run
24
+
20
25
  ```ruby
21
26
  ShellTastic::Command.run("date")
22
27
  ```
@@ -30,7 +35,18 @@ The above will return an Array of hash meta-data.
30
35
  For example, the above command's return would look something like this:
31
36
 
32
37
  ```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}]
38
+ [
39
+ {
40
+ :output=>"Sun Feb 3 17:41:45 EST 2013",
41
+ :pid=>17507,
42
+ :command => "date",
43
+ :error=>false,
44
+ :start=>2013-02-03 17:41:45 -0500,
45
+ :stop=>2013-02-03 17:41:45 -0500,
46
+ :total_time=>0.004405272,
47
+ :exitstatus=>0
48
+ }
49
+ ]
34
50
  ```
35
51
 
36
52
  You can also pass multiple commands separated by commas or pass an array.
@@ -44,7 +60,74 @@ ShellTastic::Command.run(["date", "whoami"])
44
60
  ```
45
61
 
46
62
  ```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}]
63
+ [
64
+ {
65
+ :output=>"Sat Apr 6 15:26:05 EDT 2013",
66
+ :pid=>92558,
67
+ :error=>false,
68
+ :start=>2013-04-06 15:26:05 -0400,
69
+ :stop=>2013-04-06 15:26:05 -0400,
70
+ :command=>"date",
71
+ :total_time=>0.010004,
72
+ :exitstatus=>0
73
+ },
74
+
75
+ {
76
+ :output=>"bradleydsmith",
77
+ :pid=>92559,
78
+ :error=>false,
79
+ :start=>2013-04-06 15:26:05 -0400,
80
+ :stop=>2013-04-06 15:26:05 -0400,
81
+ :command=>"whoami",
82
+ :total_time=>0.008262,
83
+ :exitstatus=>0
84
+ }
85
+ ]
86
+ ```
87
+
88
+ ### Start
89
+ Start will run a command in the background and return the pid immediately.
90
+
91
+ It takes the same command arguments as `#run`
92
+
93
+ The parent process (you) will not wait for the child to finish or return any information.
94
+
95
+ This is useful if you want to run a command, but dont care about the output or exit status.
96
+
97
+ __BEWARE__ of long running commands that could fail. ShellTastic detaches itself from the child command.
98
+
99
+
100
+
101
+ ```ruby
102
+ ShellTastic::Command.start("sleep 10; date")
103
+ ```
104
+ or
105
+
106
+ ```ruby
107
+ ShellTastic::Command.start(["sleep 10", "date"])
108
+ ```
109
+
110
+ The above will return an Array of hash meta-data.
111
+
112
+ ```ruby
113
+ [{ :output, :pid, :error, :start, :stop, :total_time, :exitstatus, :command }]
114
+ ```
115
+
116
+ For example, the above command's return would look something like this:
117
+
118
+ ```ruby
119
+ [
120
+ {
121
+ :output=>nil,
122
+ :pid=>17507,
123
+ :error=>false,
124
+ :start=>2013-02-03 17:41:45 -0500,
125
+ :stop=>2013-02-03 17:41:45 -0500,
126
+ :command=>"sleep 10; date",
127
+ :total_time=>0.004405272,
128
+ :exitstatus=>nil
129
+ }
130
+ ]
48
131
  ```
49
132
 
50
133
 
@@ -37,6 +37,39 @@ 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
40
73
  end
41
74
  end
42
75
  end
@@ -1,3 +1,3 @@
1
1
  module ShellTastic
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0"
3
3
  end
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
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) }
@@ -7,20 +7,20 @@ describe ShellTastic::OutputFormatter do
7
7
  pid: "10000000",
8
8
  error: "No such file or directory")
9
9
  end
10
- it "should return a hash" do
11
- @result.inspect.should be_kind_of(Hash)
10
+ it "returns a hash" do
11
+ expect(@result.inspect).to be_kind_of(Hash)
12
12
  end
13
13
 
14
- it "should allow to add key value pairs" do
14
+ it "allows to add key value pairs" do
15
15
  @result.command = "date"
16
- @result.inspect[:command].should eq("date")
16
+ expect(@result.inspect[:command]).to eq("date")
17
17
  end
18
18
 
19
- it "should have total time" do
19
+ it "contains total time" do
20
20
  timer = ShellTastic::Timer.new
21
21
  @result.start = timer.start
22
22
  @result.stop = timer.stop
23
23
  @result.total_time = timer.total_time
24
- @result.total_time.should_not be_nil
24
+ expect(@result.total_time).to_not be_nil
25
25
  end
26
26
  end
@@ -1,43 +1,64 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ShellTastic do
4
- it "should run a shell command" do
4
+ it "runs a shell command"do
5
5
  result = ShellTastic::Command.run("ls -l").first
6
- result.fetch(:exitstatus).should eq(0)
6
+ expect(result.fetch(:exitstatus)).to eq(0)
7
7
  end
8
8
 
9
- it "should run multiple commands" do
9
+ it "runs multiple commands"do
10
10
  result = ShellTastic::Command.run("ls -l", "date")
11
- result.size.should eq(2)
11
+ expect(result.size).to eq(2)
12
12
  end
13
13
 
14
- it "should run take an array of commands to run" do
14
+ it "takes an array of commands to run"do
15
15
  result = ShellTastic::Command.run(["ls -l", "date"])
16
- result.size.should eq(2)
16
+ expect(result.size).to eq(2)
17
17
  end
18
18
 
19
19
 
20
- it "should raise a command exception" do
20
+ it "raises a command exception"do
21
21
  expect {
22
- result = ShellTastic::Command.run("lss -l")
22
+ result = ShellTastic::Command.run("lss -l")
23
23
  }.to raise_error(ShellTastic::CommandException)
24
24
  end
25
25
 
26
- it "should alert if command is empty or nil" do
26
+ it "alerts if command is empty or nil"do
27
27
  expect {
28
28
  ShellTastic::Command.run("")
29
29
  }.to raise_error(ShellTastic::CommandException)
30
30
  end
31
31
 
32
- it "should return `false` for error if there is not any errors" do
32
+ it "returns `false` for error if there is not any errors"do
33
33
  result = ShellTastic::Command.run("date").first
34
- result[:error].should eq(false)
34
+ expect(result[:error]).to eq(false)
35
35
  end
36
36
 
37
- it "should return error" do
38
- result = ShellTastic::Command.run("du -sh /tmp/foos").first
39
- result[:error].should_not eq(false)
37
+ it "returns an error and exit status"do
38
+ result = ShellTastic::Command.run("du -sh /tmp/inotexist").first
39
+ expect(result[:error]).not_to be_nil
40
+ expect(result[:exitstatus]).to eq(1)
40
41
  end
41
42
 
43
+ # fire and forget
44
+ it "fires a command in the background and has a pid"do
45
+ result = ShellTastic::Command.start("ls -al /").first
46
+ expect(result[:pid]).not_to be_nil
47
+ end
48
+
49
+ it "fires a command in the background and has a command populated"do
50
+ result = ShellTastic::Command.start("ls -al /").first
51
+ expect(result[:command]).to eq("ls -al /")
52
+ end
53
+
54
+ it "fires a command in the background and has no ouput"do
55
+ result = ShellTastic::Command.start("ls -al /").first
56
+ expect(result[:output]).to be_nil
57
+ end
42
58
 
59
+ it "fires a command in the background and raises an error"do
60
+ expect {
61
+ ShellTastic::Command.start("foobar").first
62
+ }.to raise_error(ShellTastic::CommandException)
63
+ end
43
64
  end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@
7
7
  require 'shelltastic'
8
8
 
9
9
  RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
10
  config.run_all_when_everything_filtered = true
12
11
  config.filter_run :focus
13
12
 
data/spec/timer_spec.rb CHANGED
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ShellTastic::Timer do
4
- it "should report start time" do
4
+ it "reports start time" do
5
5
  start = ShellTastic::Timer.new.start
6
- start.class.should eq(Time)
6
+ expect(start.class).to eq(Time)
7
7
  end
8
8
 
9
- it "should report stop time" do
9
+ it "reports the stop time" do
10
10
  stop = ShellTastic::Timer.new.stop
11
- stop.class.should eq(Time)
11
+ expect(stop.class).to eq(Time)
12
12
  end
13
13
 
14
- it "should report total time" do
14
+ it "reports total time" do
15
15
  timer = ShellTastic::Timer.new
16
16
  start = timer.start
17
17
  sleep 2
18
18
  stop = timer.stop
19
19
  total = timer.total_time
20
- total.round.should eq(2)
20
+ expect(total.round).to eq(2)
21
21
  end
22
22
 
23
23
  end
metadata CHANGED
@@ -1,66 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelltastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.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: 2024-01-13 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
+ - ".github/workflows/ruby.yml"
64
+ - ".gitignore"
65
+ - ".rspec"
64
66
  - CHANGELOG.md
65
67
  - Gemfile
66
68
  - LICENSE.txt
@@ -79,29 +81,28 @@ files:
79
81
  - spec/spec_helper.rb
80
82
  - spec/timer_spec.rb
81
83
  - tags
82
- homepage: ''
84
+ homepage: https://github.com/bradleyd/shelltastic
83
85
  licenses: []
84
86
  metadata: {}
85
- post_install_message:
87
+ post_install_message:
86
88
  rdoc_options: []
87
89
  require_paths:
88
90
  - lib
89
91
  required_ruby_version: !ruby/object:Gem::Requirement
90
92
  requirements:
91
- - - '>='
93
+ - - ">="
92
94
  - !ruby/object:Gem::Version
93
95
  version: '0'
94
96
  required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  requirements:
96
- - - '>='
98
+ - - ">="
97
99
  - !ruby/object:Gem::Version
98
100
  version: '0'
99
101
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.1.11
102
- signing_key:
102
+ rubygems_version: 3.3.26
103
+ signing_key:
103
104
  specification_version: 4
104
- summary: Shelltastic is a simple *nix shell wrapper
105
+ summary: Shelltastic is a simple *nix shell wrapper.
105
106
  test_files:
106
107
  - spec/output_formatter_spec.rb
107
108
  - spec/shelltastic_spec.rb