doit 0.2.8 → 1.0.1
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 +5 -5
- data/.doit/hello +1 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +10 -0
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +17 -3
- data/.watchr +11 -7
- data/Gemfile +3 -9
- data/Gemfile.lock +38 -16
- data/LICENSE +1 -1
- data/README.md +10 -3
- data/bin/doit +14 -10
- data/doit.gemspec +21 -15
- data/lib/doit.rb +24 -17
- data/lib/globals.rb +11 -1
- data/lib/import.rb +22 -13
- data/lib/my.rb +7 -5
- data/lib/run.rb +13 -10
- data/lib/what.rb +25 -21
- data/test/doit_test.rb +25 -12
- data/test/import_test.rb +10 -10
- data/test/my_test.rb +6 -6
- data/test/run_test.rb +10 -10
- data/test/test_helper.rb +5 -3
- data/test/what_test.rb +18 -19
- metadata +61 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 062ff1abf6d388eaef7a3bc4ce063c24e2c7b99deff85250dbb0b499170b1200
|
4
|
+
data.tar.gz: e2f62709fda2f9e1deb32daeb0026ea9c58c8dc64751c877d275be95d546dc10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e90e343ee283fe75597223adc64937058647e243b810872aca1f08bf8cfac7708846e89002de4823aba8d40063113a4f7c30a0a44c7a507853557cdbb7b201d
|
7
|
+
data.tar.gz: 6a3590e52412da8e5f55532c04a784d65f36e19915e8779714c0ea2ebad8df3997cf294dfa44c456ea8ef96e1f8da43b1290f67b27883b888f293cee0eccdcfb
|
data/.doit/hello
CHANGED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails-
|
1
|
+
rails-6.1
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.2
|
1
|
+
ruby-2.7.2
|
data/.travis.yml
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
2
|
+
|
3
|
+
#bundler_args: --without production
|
4
|
+
bundle config set without production
|
5
|
+
script: "bundle exec rake test"
|
6
|
+
|
3
7
|
rvm:
|
4
|
-
|
5
|
-
- 2.
|
8
|
+
- 2.7.2 # 2020-10-26
|
9
|
+
# - 2.6.6 # 2020-07-17
|
10
|
+
# - 2.6.5 # 2019-10-29
|
11
|
+
# - 2.6.4 # 2019-10-15
|
12
|
+
# - 2.6.3 # 2019-06-21
|
13
|
+
# - 2.6.1
|
14
|
+
# - 2.5.1
|
15
|
+
# - 2.5.0
|
16
|
+
# - 2.4.1
|
17
|
+
# - 2.3.0 # tested; no longer in CI
|
18
|
+
# - 2.2.3 # tested; no longer in CI
|
19
|
+
# - 2.0.0 # tested; no longer in CI
|
6
20
|
|
7
21
|
notifications:
|
8
22
|
email: false
|
data/.watchr
CHANGED
@@ -16,31 +16,35 @@ end
|
|
16
16
|
|
17
17
|
def run_it(type, file)
|
18
18
|
case type
|
19
|
-
when 'test'; run %Q
|
19
|
+
when 'test'; run %Q(ruby -I"lib:test" -r rubygems #{file})
|
20
20
|
else; puts "#{H} unknown type: #{type}, file: #{file}"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def run_all_tests
|
25
25
|
puts "\n#{HH} Running all tests #{HH}\n"
|
26
|
-
%w
|
26
|
+
%w[test].each { |dir| run "rake #{dir}" if File.exist?(dir) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def run_matching_files(base)
|
30
30
|
base = base.split('_').first
|
31
|
-
%w
|
31
|
+
%w[test spec].each { |type|
|
32
32
|
files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
|
33
33
|
run_it type, files.join(' ') unless files.empty?
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
37
|
-
%w
|
37
|
+
%w[test spec].each { |type|
|
38
38
|
watch("#{type}/#{type}_helper\.rb") { run_all_tests }
|
39
39
|
watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
|
40
|
+
watch("#{type}/data/(.*)\.rb") { |match|
|
41
|
+
m1 = match[1]
|
42
|
+
run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
|
43
|
+
}
|
40
44
|
}
|
41
|
-
%w
|
42
|
-
watch("
|
43
|
-
run_matching_files(
|
45
|
+
%w[rb erb haml slim].each { |type|
|
46
|
+
watch("app/.*/(.*)\.#{type}") { |match|
|
47
|
+
run_matching_files(match[1])
|
44
48
|
}
|
45
49
|
}
|
46
50
|
|
data/Gemfile
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
gemspec
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem 'simplecov', require: false
|
7
|
-
end
|
8
|
-
|
9
|
-
group :test, :development do
|
10
|
-
gem 'rake'
|
11
6
|
gem 'observr'
|
12
|
-
gem '
|
7
|
+
gem 'rubocop', require: false
|
8
|
+
gem 'simplecov', require: false
|
13
9
|
end
|
14
|
-
|
15
|
-
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,56 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
doit (0.
|
4
|
+
doit (1.0.1)
|
5
5
|
micro-optparse (~> 1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
micro-optparse (1.2.
|
13
|
-
minitest (5.
|
10
|
+
ast (2.4.2)
|
11
|
+
docile (1.3.5)
|
12
|
+
micro-optparse (1.2.1)
|
13
|
+
minitest (5.14.4)
|
14
14
|
observr (1.0.5)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
parallel (1.20.1)
|
16
|
+
parser (3.0.1.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
rainbow (3.0.0)
|
19
|
+
rake (13.0.3)
|
20
|
+
regexp_parser (2.1.1)
|
21
|
+
rexml (3.2.5)
|
22
|
+
rubocop (1.13.0)
|
23
|
+
parallel (~> 1.10)
|
24
|
+
parser (>= 3.0.0.0)
|
25
|
+
rainbow (>= 2.2.2, < 4.0)
|
26
|
+
regexp_parser (>= 1.8, < 3.0)
|
27
|
+
rexml
|
28
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
29
|
+
ruby-progressbar (~> 1.7)
|
30
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
31
|
+
rubocop-ast (1.4.1)
|
32
|
+
parser (>= 2.7.1.5)
|
33
|
+
ruby-progressbar (1.11.0)
|
34
|
+
simplecov (0.21.2)
|
35
|
+
docile (~> 1.1)
|
36
|
+
simplecov-html (~> 0.11)
|
37
|
+
simplecov_json_formatter (~> 0.1)
|
38
|
+
simplecov-html (0.12.3)
|
39
|
+
simplecov_json_formatter (0.1.2)
|
40
|
+
unicode-display_width (2.0.0)
|
21
41
|
|
22
42
|
PLATFORMS
|
23
|
-
|
43
|
+
x86_64-linux
|
24
44
|
|
25
45
|
DEPENDENCIES
|
46
|
+
bundler (~> 2)
|
26
47
|
doit!
|
27
|
-
micro-optparse
|
28
|
-
minitest
|
48
|
+
micro-optparse (~> 1)
|
49
|
+
minitest (~> 5)
|
29
50
|
observr
|
30
|
-
rake
|
51
|
+
rake (~> 13)
|
52
|
+
rubocop
|
31
53
|
simplecov
|
32
54
|
|
33
55
|
BUNDLED WITH
|
34
|
-
|
56
|
+
2.2.6
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,10 @@ Executes good old shell/bash scripts locally as well as remotely.
|
|
5
5
|
The environment is set by a ".yml" configuration file.
|
6
6
|
An array environment variable triggers multiple calls of the script.
|
7
7
|
|
8
|
+
The "where" in the configuration indicates where to run the script.
|
9
|
+
|
10
|
+
See examples below.
|
11
|
+
|
8
12
|
Installation
|
9
13
|
------------
|
10
14
|
gem install doit
|
@@ -19,22 +23,25 @@ Options
|
|
19
23
|
-------
|
20
24
|
-l, --[no-]list Lists available scripts
|
21
25
|
-r, --remote ["host"] remote host or comma separated hosts
|
26
|
+
-e, --[no-]each Lists each remote command (no execution)
|
22
27
|
-s, --[no-]silent run silently; suppress output
|
23
28
|
-v, --[no-]verbose Enable verbose output
|
24
29
|
-n, --[no-]noop Suppress execution of commannds
|
25
30
|
-h, --help Show this message
|
26
31
|
-V, --version Print version
|
27
32
|
|
33
|
+
|
28
34
|
File Structure
|
29
35
|
--------------
|
30
36
|
~/.doit/deploy # chmod +x .doit/deploy
|
31
37
|
~/.doit/deploy.yml
|
32
|
-
$PROJ/.doit/deploy.yml # overwrites
|
33
|
-
$PROJ/.doit/push # chmod +x .doit/
|
38
|
+
$PROJ/.doit/deploy.yml # overwrites $HOME(~/) script/configuration
|
39
|
+
$PROJ/.doit/push # chmod +x .doit/push
|
34
40
|
$PROJ/.doit/push.yml
|
35
41
|
|
36
42
|
$PROJ/.doit/push
|
37
43
|
----------------
|
44
|
+
#! /bin/sh
|
38
45
|
if ! (git status | grep 'nothing to commit'); then
|
39
46
|
echo "push: commits are pending"
|
40
47
|
exit 1
|
@@ -68,4 +75,4 @@ $PROJ/.doit/push
|
|
68
75
|
- bob@sample.com
|
69
76
|
- alice@customer.com
|
70
77
|
|
71
|
-
Copyright (c) 2014 [Dittmar Krall], released under the MIT license
|
78
|
+
Copyright (c) 2014-2019 [Dittmar Krall], released under the MIT license.
|
data/bin/doit
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
4
|
-
$:.unshift lib unless $:.include?(lib)
|
3
|
+
lib = File.expand_path('../lib/', __dir__)
|
4
|
+
# $:.unshift lib unless $:.include?(lib)
|
5
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
6
|
|
6
7
|
require 'doit'
|
7
8
|
require 'micro-optparse'
|
8
9
|
require 'globals'
|
10
|
+
require 'what'
|
9
11
|
|
10
12
|
options = Parser.new do |p|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
p.banner = 'Usage: doit script... [options] # execute locally or remotely'
|
14
|
+
p.version = "doit #{Globals::VERSION}"
|
15
|
+
p.option :list, 'Lists available scripts'
|
16
|
+
p.option :each, 'Lists each remote command (no execution)'
|
17
|
+
p.option :remote, 'Remote host or comma separated hosts',
|
18
|
+
default: '...', optional: true
|
19
|
+
p.option :silent, 'Run silently; suppress output'
|
20
|
+
p.option :verbose, 'Enable verbose output'
|
21
|
+
p.option :noop, 'Suppress execution of commannds'
|
18
22
|
end.process!
|
19
23
|
|
20
24
|
Doit.start(options)
|
data/doit.gemspec
CHANGED
@@ -1,22 +1,28 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
2
|
require 'globals'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'doit'
|
6
|
+
s.version = Globals::VERSION
|
7
|
+
s.summary = 'Simple local & remote script executor'
|
8
|
+
s.description = 'Run good old shell/bash scripts locally or remotely(ssh).'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
s.authors = ['Dittmar Krall']
|
11
|
+
s.email = 'dittmar.krall@matique.de'
|
12
|
+
s.homepage = 'http://www.matique.de'
|
13
|
+
s.license = 'MIT'
|
14
14
|
|
15
|
-
|
15
|
+
s.add_dependency 'micro-optparse', '~> 1'
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- test`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`
|
20
|
+
.split("\n").map { |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
21
22
|
|
23
|
+
s.add_development_dependency 'bundler', '~> 2'
|
24
|
+
s.add_development_dependency 'rake', '~> 13'
|
25
|
+
|
26
|
+
s.add_development_dependency 'micro-optparse', '~> 1'
|
27
|
+
s.add_development_dependency 'minitest', '~> 5'
|
22
28
|
end
|
data/lib/doit.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
1
3
|
require 'my'
|
2
4
|
require 'run'
|
3
5
|
require 'import'
|
4
|
-
require 'what'
|
5
6
|
|
6
|
-
|
7
|
+
Doit = Object.new
|
8
|
+
class << Doit
|
7
9
|
|
8
|
-
def
|
10
|
+
def start(options)
|
9
11
|
@options = options
|
10
12
|
list if options[:list]
|
11
13
|
|
@@ -15,54 +17,59 @@ class Doit
|
|
15
17
|
execute(script) if script
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
@options
|
20
|
+
def options
|
21
|
+
@options ||= {}
|
22
|
+
@options
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
25
|
+
def list
|
23
26
|
hsh = Import.list
|
24
27
|
hsh.sort.each { |abb, long|
|
25
28
|
puts "#{abb}\t- #{long}"
|
26
29
|
next unless options[:verbose]
|
30
|
+
|
27
31
|
lines = `grep -i 'usage\\|summary' #{long} | grep '^#'`.split("\n")
|
28
32
|
lines.each { |line|
|
29
33
|
next unless line
|
30
34
|
next if line.empty?
|
35
|
+
|
31
36
|
puts "\t #{line}"
|
32
37
|
}
|
33
38
|
}
|
34
39
|
end
|
35
40
|
|
36
|
-
def
|
41
|
+
def execute(name)
|
37
42
|
Import.init(name)
|
38
43
|
unless Import.script
|
39
44
|
puts "doit: script '#{name}' not found"
|
40
45
|
return
|
41
46
|
end
|
42
|
-
What.init(Import.
|
47
|
+
What.init(Import.config)
|
48
|
+
|
49
|
+
What.where.each { |w| puts "doit #{name} -r #{w}" } if options[:each]
|
43
50
|
|
44
|
-
where_loop
|
51
|
+
where_loop unless options[:each]
|
45
52
|
end
|
46
53
|
|
47
54
|
private
|
48
|
-
def
|
55
|
+
def where_loop
|
49
56
|
What.where.each { |w|
|
50
57
|
matrix_loop(w)
|
51
58
|
}
|
52
59
|
end
|
53
60
|
|
54
|
-
def
|
61
|
+
def matrix_loop(where)
|
55
62
|
What.matrix.each { |mm|
|
56
63
|
prefix = mm.empty? ? '' : "#{What.to_env(mm)}\n"
|
57
64
|
|
58
65
|
What.env.each { |en|
|
59
|
-
|
66
|
+
prefix2 = en.empty? ? '' : "#{en}\n"
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
cmds = Import.script
|
69
|
+
cmds = @argv + prefix + prefix2 + cmds
|
70
|
+
Run.init cmds, where
|
71
|
+
Run.info if options[:verbose]
|
72
|
+
Run.run
|
66
73
|
}
|
67
74
|
}
|
68
75
|
end
|
data/lib/globals.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
1
3
|
module Globals
|
2
|
-
VERSION = '0.
|
4
|
+
VERSION = '1.0.1' # 2021-04-21
|
5
|
+
# VERSION = '1.0.0' # 2020-10-26
|
6
|
+
# VERSION = '0.3.9' # 2020-07-17
|
7
|
+
# VERSION = '0.3.8' # 2020-02-26
|
8
|
+
# VERSION = '0.3.7' # 2019-10-15
|
9
|
+
# VERSION = '0.3.6' # 2019-03-06
|
10
|
+
# VERSION = '0.3.5' # 2018-09-11
|
11
|
+
# VERSION = '0.3.4' # 2018-08-19
|
12
|
+
# VERSION = '0.3.3'
|
3
13
|
end
|
data/lib/import.rb
CHANGED
@@ -1,32 +1,41 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'erb'
|
3
5
|
|
4
|
-
|
6
|
+
Import = Object.new
|
7
|
+
class << Import
|
5
8
|
|
6
|
-
def
|
7
|
-
|
9
|
+
def script
|
10
|
+
@script ||= nil
|
11
|
+
@script
|
12
|
+
end
|
8
13
|
|
9
|
-
def
|
14
|
+
def config
|
15
|
+
@config ||= nil
|
16
|
+
@config
|
17
|
+
end
|
18
|
+
|
19
|
+
def init(name)
|
10
20
|
@script = read(name)
|
11
21
|
@config = ERB.new(read("#{name}.yml") || '').result
|
12
22
|
info
|
13
23
|
end
|
14
24
|
|
15
25
|
# returns Hash { 'pull' => '/home/dk/.doit/pull', ... }
|
16
|
-
def
|
26
|
+
def list
|
17
27
|
@list ||= list2
|
18
28
|
end
|
19
29
|
|
20
|
-
def
|
30
|
+
def info
|
21
31
|
return unless Doit.options[:verbose]
|
22
32
|
|
23
|
-
My.verbose
|
24
|
-
My.verbose
|
33
|
+
My.verbose 'SCRIPT', @script
|
34
|
+
My.verbose 'CONFIG(yml)', @config
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
37
|
private
|
29
|
-
def
|
38
|
+
def list2
|
30
39
|
res = {}
|
31
40
|
Pathname.pwd.descend { |dir|
|
32
41
|
doit_dir = dir + '.doit'
|
@@ -46,14 +55,14 @@ class Import
|
|
46
55
|
res
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
58
|
+
def read(name)
|
50
59
|
try_ascend(".doit/#{name}")
|
51
60
|
end
|
52
61
|
|
53
|
-
def
|
62
|
+
def try_ascend(filename)
|
54
63
|
Pathname.pwd.ascend { |dir|
|
55
64
|
str = dir + filename
|
56
|
-
return File.read(str) if File.
|
65
|
+
return File.read(str) if File.exist?(str)
|
57
66
|
}
|
58
67
|
nil
|
59
68
|
end
|
data/lib/my.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
My = Object.new
|
4
|
+
|
5
|
+
class << My
|
6
|
+
def verbose(what, txt)
|
7
|
+
marker = '*' * 4
|
5
8
|
arr = txt
|
6
|
-
arr = txt ? txt.split("\n") : ''
|
9
|
+
arr = txt ? txt.split("\n") : '' unless txt.is_a?(Array)
|
7
10
|
if arr.length > 1
|
8
11
|
puts "#{marker} #{what} #{marker}"
|
9
12
|
puts txt
|
@@ -12,5 +15,4 @@ class My
|
|
12
15
|
puts "#{marker} #{what}: #{txt}"
|
13
16
|
end
|
14
17
|
end
|
15
|
-
|
16
18
|
end
|
data/lib/run.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
# rubocop: disable all
|
2
2
|
|
3
|
-
|
3
|
+
Run = Object.new
|
4
|
+
class << Run
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
attr_reader :ssh
|
7
|
+
|
8
|
+
def init(cmds, where)
|
9
|
+
aster = '*' * 24
|
7
10
|
puts "#{aster} #{where} #{aster}"
|
8
11
|
@ssh = nil
|
9
12
|
@cmds = cmds
|
@@ -17,25 +20,25 @@ class Run
|
|
17
20
|
dir = where
|
18
21
|
end
|
19
22
|
|
20
|
-
@cmds = "cd; cd #{dir}\n" + @cmds unless dir
|
23
|
+
@cmds = "cd; cd #{dir}\n" + @cmds unless dir&.empty?
|
21
24
|
@ssh = "ssh #{host}" if host
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
27
|
+
def info
|
25
28
|
My.verbose('SSH', @ssh)
|
26
29
|
My.verbose('cmds', @cmds)
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
32
|
+
def run
|
30
33
|
here = '___EOS___'
|
31
34
|
silent = Doit.options[:silent] ? '>/dev/null' : ''
|
32
35
|
cmd = "cat <<'#{here}\' | #{@ssh} bash -i -l #{silent} 2>&1"
|
33
36
|
cmds = "#{cmd}\n#{@cmds}#{here}\n"
|
34
37
|
|
35
|
-
|
36
|
-
IO.popen(cmds) { |p| p.each { |f| puts f } }
|
37
|
-
else
|
38
|
+
if Doit.options[:noop]
|
38
39
|
My.verbose('noop', cmds)
|
40
|
+
else
|
41
|
+
IO.popen(cmds) { |p| p.each { |f| puts f } }
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
data/lib/what.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# rubocop: disable all
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'doit'
|
3
5
|
|
4
|
-
|
6
|
+
What = Object.new
|
7
|
+
class << What
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
attr_reader :matrix
|
10
|
+
attr_reader :where
|
11
|
+
attr_reader :env
|
9
12
|
|
10
|
-
def
|
13
|
+
def init(config)
|
11
14
|
@matrix = nil
|
12
15
|
@yml = (config && YAML.load(config)) || {}
|
13
16
|
|
@@ -23,37 +26,38 @@ class What
|
|
23
26
|
|
24
27
|
build_matrix
|
25
28
|
@matrix ||= []
|
26
|
-
@matrix = [@matrix] unless
|
29
|
+
@matrix = [@matrix] unless @matrix.first.is_a?(Array)
|
27
30
|
@matrix.map! { |m| m.flatten.inject({}) { |hsh, h| hsh.merge(h) } }
|
28
31
|
info
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
34
|
+
def to_env(hsh)
|
32
35
|
arr = hsh.collect { |key, value| "#{key.to_s.upcase}=#{value}" }
|
33
36
|
arr.join ' '
|
34
37
|
end
|
35
38
|
|
36
|
-
def
|
39
|
+
def info
|
37
40
|
return unless Doit.options[:verbose]
|
38
41
|
|
39
|
-
My.verbose
|
40
|
-
My.verbose
|
41
|
-
My.verbose
|
42
|
+
My.verbose 'where', @where
|
43
|
+
My.verbose 'matrix', @matrix
|
44
|
+
My.verbose 'env', @env
|
42
45
|
end
|
43
46
|
|
44
|
-
|
45
47
|
private
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def build_matrix
|
49
|
+
return if @yml.empty?
|
50
|
+
|
51
|
+
key, value = @yml.first
|
52
|
+
@yml.delete(key)
|
53
|
+
add_to_matrix(key, value)
|
54
|
+
build_matrix
|
53
55
|
end
|
54
56
|
|
55
|
-
def
|
56
|
-
arr = Array
|
57
|
+
def add_to_matrix(key, val)
|
58
|
+
arr = val.is_a?(Array) ?
|
59
|
+
val.collect { |v| [{ key => v }] } :
|
60
|
+
[{ key => val }]
|
57
61
|
@matrix = @matrix ? @matrix.product(arr) : arr
|
58
62
|
end
|
59
63
|
|
data/test/doit_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'doit'
|
3
2
|
|
4
3
|
describe Doit do
|
5
4
|
|
@@ -7,34 +6,48 @@ describe Doit do
|
|
7
6
|
Doit.start({})
|
8
7
|
end
|
9
8
|
|
10
|
-
it
|
11
|
-
out = noop {
|
9
|
+
it 'start' do
|
10
|
+
out = noop {}
|
12
11
|
assert_equal '', out
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
14
|
+
it 'options' do
|
16
15
|
assert_equal({}, Doit.options)
|
17
16
|
end
|
18
17
|
|
19
|
-
it
|
18
|
+
it 'list' do
|
20
19
|
out = noop {
|
21
20
|
Doit.list
|
22
21
|
}
|
23
|
-
assert_match
|
22
|
+
assert_match(/\/\.doit/, out)
|
24
23
|
end
|
25
24
|
|
26
|
-
it
|
27
|
-
out,
|
25
|
+
it 'execute' do
|
26
|
+
out, _err = capture_io do
|
28
27
|
Doit.execute('hello')
|
29
28
|
end
|
30
|
-
assert_match
|
29
|
+
assert_match(/\nHello\n/, out)
|
31
30
|
end
|
32
31
|
|
33
|
-
it
|
34
|
-
out,
|
32
|
+
it 'execute with unknown script' do
|
33
|
+
out, _err = capture_io do
|
35
34
|
Doit.execute('______unknown______')
|
36
35
|
end
|
37
|
-
assert_match
|
36
|
+
assert_match(/not found/, out)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'tests option --each' do
|
40
|
+
out = noop(each: true) {
|
41
|
+
Doit.execute('hello')
|
42
|
+
}
|
43
|
+
assert_match(/doit hello -r/, out)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'coverage: list; option -lv' do
|
47
|
+
out = noop(verbose: true, list: true) {
|
48
|
+
Doit.start(verbose: true, list: true)
|
49
|
+
}
|
50
|
+
assert_match(/just a test\n/, out)
|
38
51
|
end
|
39
52
|
|
40
53
|
end
|
data/test/import_test.rb
CHANGED
@@ -5,33 +5,33 @@ require 'my'
|
|
5
5
|
|
6
6
|
describe Import do
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'init fails with empty' do
|
9
9
|
assert_raises(Errno::EISDIR) { Import.init('') }
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'init' do
|
13
13
|
Import.init('hello')
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'list' do
|
17
17
|
Import.init('hello')
|
18
|
-
assert_match
|
18
|
+
assert_match(/\/\.doit\/hello$/, Import.list['hello'])
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
out = noop(
|
21
|
+
it 'info' do
|
22
|
+
out = noop(verbose: true) {
|
23
23
|
Import.init('hello')
|
24
24
|
Import.info
|
25
25
|
}
|
26
|
-
assert_match
|
27
|
-
assert_match
|
26
|
+
assert_match(/SCRIPT/, out)
|
27
|
+
assert_match(/CONFIG/, out)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'coverage: script' do
|
31
31
|
Import.script
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'coverage: config' do
|
35
35
|
Import.config
|
36
36
|
end
|
37
37
|
|
data/test/my_test.rb
CHANGED
@@ -3,20 +3,20 @@ require 'my'
|
|
3
3
|
|
4
4
|
describe My do
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'verbose' do
|
7
7
|
h = 'hello'
|
8
|
-
out,
|
8
|
+
out, _err = capture_io do
|
9
9
|
My.verbose('a', h)
|
10
10
|
end
|
11
|
-
assert_match
|
11
|
+
assert_match(/#{h}/, out)
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'verbose text' do
|
15
15
|
h = 'hello'
|
16
|
-
out,
|
16
|
+
out, _err = capture_io do
|
17
17
|
My.verbose('a', "#{h}\nx\n")
|
18
18
|
end
|
19
|
-
assert_match
|
19
|
+
assert_match(/#{h}/, out)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
data/test/run_test.rb
CHANGED
@@ -5,54 +5,54 @@ require 'doit'
|
|
5
5
|
|
6
6
|
describe Run do
|
7
7
|
|
8
|
-
it
|
9
|
-
|
8
|
+
it 'coverage #info' do
|
9
|
+
_out, _err = capture_io do
|
10
10
|
Run.init('', '')
|
11
11
|
Run.info
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it "where '' returns nil" do
|
16
|
-
|
16
|
+
_out, _err = capture_io do
|
17
17
|
Run.init('', '')
|
18
18
|
assert_equal nil, Run.ssh
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
it "where 'a' returns nil" do
|
23
|
-
|
23
|
+
_out, _err = capture_io do
|
24
24
|
Run.init('', 'a')
|
25
25
|
assert_equal nil, Run.ssh
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
it "where 'a@b' returns 'ssh a@b'" do
|
30
|
-
|
30
|
+
_out, _err = capture_io do
|
31
31
|
Run.init('', 'a@b')
|
32
32
|
assert_equal 'ssh a@b', Run.ssh
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it "where 'a@b:c' returns 'ssh a@b'" do
|
37
|
-
|
37
|
+
_out, _err = capture_io do
|
38
38
|
Run.init('', 'a@b:c')
|
39
39
|
assert_equal 'ssh a@b', Run.ssh
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
|
43
|
+
it 'coverage #run' do
|
44
|
+
_out, _err = capture_io do
|
45
45
|
Run.init('', '')
|
46
46
|
Run.run
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'coverage #run noop' do
|
51
51
|
out = noop {
|
52
52
|
Run.init('', '')
|
53
53
|
Run.run
|
54
54
|
}
|
55
|
-
assert_match
|
55
|
+
assert_match(/EOS/, out)
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,15 +4,17 @@ SimpleCov.start do
|
|
4
4
|
command_name 'Minitest'
|
5
5
|
end
|
6
6
|
|
7
|
+
require 'what'
|
8
|
+
|
7
9
|
require 'minitest/autorun'
|
8
10
|
|
9
|
-
def noop(options = {noop: true}, &block)
|
11
|
+
def noop(options = { noop: true }, &block)
|
10
12
|
return 'noop: missing block' unless block
|
11
13
|
|
12
14
|
out = '---'
|
13
15
|
Doit.stub :options, options do
|
14
|
-
out,
|
15
|
-
|
16
|
+
out, _err = capture_io do
|
17
|
+
yield
|
16
18
|
end
|
17
19
|
end
|
18
20
|
out
|
data/test/what_test.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'what'
|
3
2
|
require 'my'
|
4
3
|
|
5
4
|
describe What do
|
6
5
|
|
7
|
-
it
|
8
|
-
What.init(''
|
6
|
+
it 'is robust against empty params' do
|
7
|
+
What.init('')
|
9
8
|
assert_equal [Dir.pwd], What.where
|
10
9
|
assert_equal [{}], What.matrix
|
11
10
|
end
|
@@ -14,32 +13,32 @@ describe What do
|
|
14
13
|
assert_equal '', What.to_env({})
|
15
14
|
end
|
16
15
|
|
17
|
-
it
|
18
|
-
assert_equal 'A=1', What.to_env(
|
16
|
+
it 'to_env converts variable to uppercase' do
|
17
|
+
assert_equal 'A=1', What.to_env(a: 1)
|
19
18
|
end
|
20
19
|
|
21
|
-
it
|
22
|
-
Doit.stub :options,
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
it 'coverage: #info' do
|
21
|
+
Doit.stub :options, verbose: true do
|
22
|
+
_out, _err = capture_io do
|
23
|
+
What.init('')
|
24
|
+
What.info
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
it
|
31
|
-
What.init(
|
32
|
-
assert_equal [{
|
29
|
+
it 'builds simple matrix' do
|
30
|
+
What.init("a: 1\n")
|
31
|
+
assert_equal [{ 'a' => 1 }], What.matrix
|
33
32
|
end
|
34
33
|
|
35
|
-
it
|
36
|
-
What.init(
|
37
|
-
assert_equal [{
|
34
|
+
it 'builds matrix' do
|
35
|
+
What.init("a:\n - 1\n - 2\n")
|
36
|
+
assert_equal [{ 'a' => 1 }, { 'a' => 2 }], What.matrix
|
38
37
|
end
|
39
38
|
|
40
|
-
it
|
41
|
-
What.init(
|
42
|
-
assert_equal [{
|
39
|
+
it 'builds product matrix' do
|
40
|
+
What.init("a:\n - 1\nb:\n - 3\n - 4\n")
|
41
|
+
assert_equal [{ 'a' => 1, 'b' => 3 }, { 'a' => 1, 'b' => 4 }], What.matrix
|
43
42
|
end
|
44
43
|
|
45
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: micro-optparse
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: micro-optparse
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5'
|
27
83
|
description: Run good old shell/bash scripts locally or remotely(ssh).
|
28
84
|
email: dittmar.krall@matique.de
|
29
85
|
executables:
|
@@ -33,6 +89,8 @@ extra_rdoc_files: []
|
|
33
89
|
files:
|
34
90
|
- ".doit/hello"
|
35
91
|
- ".doit/hello.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
36
94
|
- ".ruby-gemset"
|
37
95
|
- ".ruby-version"
|
38
96
|
- ".travis.yml"
|
@@ -75,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
133
|
- !ruby/object:Gem::Version
|
76
134
|
version: '0'
|
77
135
|
requirements: []
|
78
|
-
|
79
|
-
rubygems_version: 2.4.2
|
136
|
+
rubygems_version: 3.2.6
|
80
137
|
signing_key:
|
81
138
|
specification_version: 4
|
82
139
|
summary: Simple local & remote script executor
|