watchly-cli 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8ba362e4fd559aab05ea2ccedf8b60a68fa0f394621b6b69abf0c470ee25170
4
+ data.tar.gz: 16344f7295f4d3803260a6fb10ed0d98906eabc8e6949fe73b2266058dc90cbd
5
+ SHA512:
6
+ metadata.gz: 6c8acb838e6d54b3fc1d34870e2082ad73c3eb020e1dddf22d9aa31540f8e3fc3ee8c3c5289db9913d1f3d55b1871c226c85a1ce8269e069ffa2bfcf7120b754
7
+ data.tar.gz: 2b6e914589926b03cea07b5948ff3e8d9b71f61fb8c542540e8320df63ac6231776fca06d065ceaea09c373a36140a8a3ed2c56b1ee28a4b25437f4ce3e4b081
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Watchly CLI
2
+
3
+ [Watchly][watchly] is a lightweight, dependency-free, polling-based file watcher for Ruby.
4
+ It watches one or more glob patterns and reports changes.
5
+
6
+ This is its command line interface.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ gem install watchly-cli
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ <!-- START USAGE -->
17
+ ```console
18
+ $ watchly --help
19
+ watchly — run a command when files change
20
+
21
+ Watches files matching one or more glob patterns and runs a command when
22
+ they change.
23
+
24
+ When the command runs, environment variables are set with the list of
25
+ changed files (see below).
26
+
27
+ Usage:
28
+ watchly COMMAND [options] [GLOB...]
29
+
30
+ Options:
31
+ -i, --interval N
32
+ Loop interval in seconds [default: 1]
33
+
34
+ -q, --quiet
35
+ Print less to screen
36
+
37
+ -e, --each
38
+ Run the command once per added or changed file
39
+
40
+ -m, --immediate
41
+ Execute the command before watching
42
+
43
+ -h --help
44
+ Show this help
45
+
46
+ Parameters:
47
+ COMMAND
48
+ Command to run on change
49
+
50
+ GLOB
51
+ One or more glob patterns [default: *.*]
52
+
53
+ Environment Variables:
54
+ WATCHLY_FILES
55
+ Added and modified files, one per line
56
+
57
+ WATCHLY_ADDED
58
+ Added files, one per line
59
+
60
+ WATCHLY_MODIFIED
61
+ Modified files, one per line
62
+
63
+ WATCHLY_REMOVED
64
+ Removed files, one per line
65
+
66
+ WATCHLY_FILE
67
+ The file currently being processed (only with --each)
68
+
69
+ Examples:
70
+ watchly 'echo "$WATCHLY_FILES"' 'spec/**/*.rb' 'lib/**/*.*'
71
+
72
+ ```
73
+ <!-- END USAGE -->
74
+
75
+
76
+ ## Contributing / Support
77
+
78
+ If you experience any issue, have a question, or if you wish
79
+ to contribute, feel free to [open an issue][issues].
80
+
81
+ [watchly]: https://github.com/dannyben/watchly
82
+ [issues]: https://github.com/dannyben/watchly-cli/issues
data/bin/watchly ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'colsole'
3
+ require 'watchly/cli'
4
+
5
+ include Colsole
6
+
7
+ router = Watchly::CLI::CommandLine.router
8
+
9
+ begin
10
+ exit router.run ARGV
11
+ rescue => e
12
+ puts e.backtrace.reverse if ENV['DEBUG']
13
+ say! "r`#{e.class}: #{e.message}`"
14
+ exit 1
15
+ end
@@ -0,0 +1,95 @@
1
+ require 'mister_bin'
2
+
3
+ module Watchly
4
+ module CLI
5
+ class Command < MisterBin::Command
6
+ summary 'watchly — run a command when files change'
7
+ version "#{VERSION} (watchly #{Watchly::VERSION})"
8
+
9
+ help <<~HELP
10
+ Watches files matching one or more glob patterns and runs a command when
11
+ they change.
12
+
13
+ When the command runs, environment variables are set with the list of
14
+ changed files (see below).
15
+ HELP
16
+
17
+ usage 'watchly COMMAND [options] [GLOB...]'
18
+ usage 'watchly --version | --help'
19
+
20
+ param 'COMMAND', 'Command to run on change'
21
+ param 'GLOB', 'One or more glob patterns [default: *.*]'
22
+
23
+ option '-i --interval N', 'Loop interval in seconds [default: 1]'
24
+ option '-q --quiet', 'Print less to screen'
25
+ option '-e --each', 'Run the command once per added or changed file'
26
+ option '-m --immediate', 'Execute the command before watching'
27
+
28
+ environment 'WATCHLY_FILES', 'Added and modified files, one per line'
29
+ environment 'WATCHLY_ADDED', 'Added files, one per line'
30
+ environment 'WATCHLY_MODIFIED', 'Modified files, one per line'
31
+ environment 'WATCHLY_REMOVED', 'Removed files, one per line'
32
+ environment 'WATCHLY_FILE', 'The file currently being processed (only with --each)'
33
+
34
+ example %[watchly 'echo "$WATCHLY_FILES"' 'spec/**/*.rb' 'lib/**/*.*']
35
+
36
+ def run
37
+ run_command if immediate?
38
+ watch
39
+ rescue Interrupt
40
+ say "\ngoodbye"
41
+ end
42
+
43
+ private
44
+
45
+ def watch
46
+ say 'watching...'
47
+ watcher.on_change do |changes|
48
+ show_changes changes unless quiet?
49
+
50
+ if each?
51
+ run_each(changes)
52
+ else
53
+ run_command env_from_changes(changes)
54
+ end
55
+ end
56
+ end
57
+
58
+ def env_from_changes(changes)
59
+ {
60
+ 'WATCHLY_FILES' => changes.files.join("\n"),
61
+ 'WATCHLY_ADDED' => changes.added.join("\n"),
62
+ 'WATCHLY_MODIFIED' => changes.modified.join("\n"),
63
+ 'WATCHLY_REMOVED' => changes.removed.join("\n"),
64
+ }
65
+ end
66
+
67
+ def show_changes(changes)
68
+ changes.added.each { say "gb`+ #{it}`" }
69
+ changes.modified.each { say "bb`* #{it}`" }
70
+ changes.removed.each { say "rb`- #{it}`" }
71
+ end
72
+
73
+ def run_command(env = {})
74
+ success = system env, command
75
+ { status: success ? 0 : 1 }
76
+ end
77
+
78
+ def run_each(changes)
79
+ changes.files.each do |file|
80
+ env = env_from_changes(changes).merge('WATCHLY_FILE' => file)
81
+ run_command(env)
82
+ end
83
+ end
84
+
85
+ def watcher = @watcher ||= Watchly::Watcher.new(globs, interval:)
86
+
87
+ def command = args['COMMAND']
88
+ def globs = args['GLOB'] || '*.*'
89
+ def interval = args['--interval'].to_i
90
+ def quiet? = args['--quiet']
91
+ def each? = args['--each']
92
+ def immediate? = args['--immediate']
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,9 @@
1
+ module Watchly
2
+ module CLI
3
+ class CommandLine
4
+ def self.router
5
+ MisterBin::Runner.new handler: Command
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Watchly
2
+ module CLI
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'mister_bin'
2
+
3
+ require 'watchly'
4
+ require 'watchly/version'
5
+ require 'watchly/cli/version'
6
+ require 'watchly/cli/command'
7
+ require 'watchly/cli/command_line'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watchly-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: colsole
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: mister_bin
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - !ruby/object:Gem::Dependency
41
+ name: watchly
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.0
54
+ description: A small, dependency-free, polling-based executable that watches one or
55
+ more glob patterns and reports on change
56
+ email: db@dannyben.com
57
+ executables:
58
+ - watchly
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - bin/watchly
64
+ - lib/watchly/cli.rb
65
+ - lib/watchly/cli/command.rb
66
+ - lib/watchly/cli/command_line.rb
67
+ - lib/watchly/cli/version.rb
68
+ homepage: https://github.com/dannyben/watchly-cli
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ bug_tracker_uri: https://github.com/dannyben/watchly-cli/issues
73
+ changelog_uri: https://github.com/dannyben/watchly-cli/blob/master/CHANGELOG.md
74
+ source_code_uri: https://github.com/dannyben/watchly-cli
75
+ rubygems_mfa_required: 'true'
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 4.0.3
91
+ specification_version: 4
92
+ summary: Lightweight, polling-based file system watcher CLI
93
+ test_files: []