guard-super_shell 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 +7 -0
- data/LICENSE +20 -0
- data/README.md +103 -0
- data/lib/guard/super_shell.rb +59 -0
- data/lib/guard/super_shell/templates/Guardfile +6 -0
- data/lib/guard/super_shell/version.rb +5 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c62d9073bb7df0311b628dcc45b96f19b43826fa2b88643e31042b60eec3c48
|
4
|
+
data.tar.gz: 8fe11c8bf9f52d721884174e29a173172919452f2ccd03410000fb75c72180fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e96a60669d3c81fe82cd32919e09ea3fe19d889cdf279b626acc68562e11e9b274e4a47413a3e93290fbb7eb2e2a7329a6952e6520da5686f3f085bd54c09b50
|
7
|
+
data.tar.gz: 74b11dba24d807fd9e8a53579448ccf8426767d2b94d9d567b3d47ce3f6ac0c265f711a10d6e3e0bc209bb642b215bc3add135eb86476ab33b7d2c1f0e16f894
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Joshua Hawxwell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# guard-super_shell
|
2
|
+
|
3
|
+
Shell commands triggered by files changing.
|
4
|
+
|
5
|
+
- [ ] TODO: Update specs
|
6
|
+
|
7
|
+
## Differences from [guard-shell](https://github.com/guard/guard-shell)
|
8
|
+
|
9
|
+
- Runs the shell command on a set of changes instead of once per file (like all other guards)
|
10
|
+
- `run_on_start` option runs the command once, not once per file that will be watched
|
11
|
+
- Shows notifications based on the command status, no additions to the DSL
|
12
|
+
- Last line of command output is shown in the notification
|
13
|
+
- `name` option provides a meaningful name for each instance which is displayed in console and notifications
|
14
|
+
- Runs on all file changes, not just modifications of existing files.
|
15
|
+
|
16
|
+
## Install
|
17
|
+
|
18
|
+
Make sure you have [guard](http://github.com/guard/guard) installed.
|
19
|
+
|
20
|
+
Install the gem with:
|
21
|
+
|
22
|
+
gem install guard-super_shell
|
23
|
+
|
24
|
+
Or add it to your Gemfile:
|
25
|
+
|
26
|
+
gem 'guard-super_shell'
|
27
|
+
|
28
|
+
And then add a basic setup to your Guardfile:
|
29
|
+
|
30
|
+
guard init shell
|
31
|
+
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
If you can do something in your shell, or in ruby, you can do it when files change
|
36
|
+
with guard-super_shell. It executes a shell command built by the `command` block you provide,
|
37
|
+
if one or more matching files change.
|
38
|
+
The output of the command is shown in the console.
|
39
|
+
It shows a notification based on the return status of that shell command.
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
guard(
|
43
|
+
:shell,
|
44
|
+
name: "GraphQL Schema",
|
45
|
+
command: proc { |files| "bin/rake graphql:schema:idl" },
|
46
|
+
) do
|
47
|
+
watch %r{app/graphql.+}
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
will run a rake task and print the returned output from the rake task to the console.
|
52
|
+
|
53
|
+
You can also return an array of command components. To have it run at startup:
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
guard(
|
57
|
+
:shell,
|
58
|
+
name: "GraphQL Schema",
|
59
|
+
run_at_start: true,
|
60
|
+
command: proc { |files| ["bin/rake", "graphql:schema:idl"] },
|
61
|
+
) do
|
62
|
+
watch %r{app/graphql.+}
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Examples
|
67
|
+
|
68
|
+
#### Saying the Name of the File(s) You Changed
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
guard(
|
72
|
+
:shell,
|
73
|
+
name: "Speak Changes",
|
74
|
+
command: proc { |files| "say -v cello #{files.join(" ")}" },
|
75
|
+
) do
|
76
|
+
watch /(.*)/
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Check Syntax of a Ruby File
|
81
|
+
|
82
|
+
``` ruby
|
83
|
+
guard(
|
84
|
+
:shell ,
|
85
|
+
name: "Check Ruby Syntax",
|
86
|
+
command: proc { |files| "ruby -c #{files.join(' ')}" },
|
87
|
+
) do
|
88
|
+
watch /.*\.rb$/
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Run tests on corresponding file
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
guard(
|
96
|
+
:shell ,
|
97
|
+
name: "Run Corresponding Test",
|
98
|
+
command: proc { |files| "bin/test #{files.join(' ')}" },
|
99
|
+
) do
|
100
|
+
# Translate the matching changed file path to get the path of the corresponding test file.
|
101
|
+
watch %r{app/stuff/(.*)\.rb$} { |m| "spec/stuff/#{m[1]}_test.rb" }
|
102
|
+
end
|
103
|
+
```
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'guard/compat/plugin'
|
2
|
+
require 'guard/super_shell/version'
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class SuperShell < Plugin
|
7
|
+
def start
|
8
|
+
if options[:run_at_start]
|
9
|
+
Compat::UI.info "#{name} running at start"
|
10
|
+
run_command
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_on_changes(files)
|
18
|
+
Compat::UI.info "#{name}: #{files.join}"
|
19
|
+
run_command(files)
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_all
|
23
|
+
run_command
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
options[:name] || "shell"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def run_command(files = [])
|
33
|
+
command = options[:command].call(files)
|
34
|
+
(stdin, stdout_and_stderr, thread) = Open3.popen2e(command)
|
35
|
+
output = stdout_and_stderr.read
|
36
|
+
puts output
|
37
|
+
|
38
|
+
if thread.value.success?
|
39
|
+
Compat::UI.notify(output.lines.last, title: name, type: :success) if notify?
|
40
|
+
else
|
41
|
+
Compat::UI.notify(output.lines.last, title: name, type: :failed) if notify?
|
42
|
+
throw :task_has_failed
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
msg = "#{e.class.name}: #{e.message}"
|
46
|
+
Compat::UI.error "#{name}: raised error #{msg}"
|
47
|
+
Compat::UI.notify(msg, title: name, type: :failed) if notify?
|
48
|
+
throw :task_has_failed
|
49
|
+
end
|
50
|
+
|
51
|
+
def notify?
|
52
|
+
options.fetch(:notification, true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def run_at_start?
|
56
|
+
options.fetch(:run_at_start, false)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-super_shell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Daugherty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: guard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-compat
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: |2
|
42
|
+
Runs a shell command when specific files change. Shows the output
|
43
|
+
and a notification based on the command's return status.
|
44
|
+
Runs command once per _set_ of file changes.
|
45
|
+
email: robin@robindaugherty.net
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- lib/guard/super_shell.rb
|
53
|
+
- lib/guard/super_shell/templates/Guardfile
|
54
|
+
- lib/guard/super_shell/version.rb
|
55
|
+
homepage: http://github.com/RobinDaugherty/guard-super_shell
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.1.4
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Guard plugin that simply runs a shell command
|
78
|
+
test_files: []
|