doit 0.2.8 → 0.3.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
2
  SHA1:
3
- metadata.gz: 21d9aef9f7bf2563d6dbaf3125b06bb63f2c51c8
4
- data.tar.gz: 927348c96fa1346a51c3f5ee19c0ca23db64698b
3
+ metadata.gz: 7e3e55b5782a334d1ace53286a138bdd935a4d09
4
+ data.tar.gz: 4fa3b68d8f34263279ae3dff8e1d87a1c7dfbfa0
5
5
  SHA512:
6
- metadata.gz: 9d68dd4dec5bb8d71ba463b80fd99e545e531331dd275a277026377675a61b540e38dadc197177a298bd070985d4f613a02fcfd3259feb577c4b0574ee59a1b6
7
- data.tar.gz: 52df7f1d400a16564168e1fb253020a17bf015877915fe3b7b22a5897ed69683d44745231cead599c5dd732b1f390248b537c3c57f0e580a71c40049e3b8f2c9
6
+ metadata.gz: ded0af93c825b472874ea32daae00c5e0821ad0132c474fc308d6354e174ed782a1d28a6e5f6548de84cd5e9d7d3f6500104a800970a12a84502d6c72e0bfb39
7
+ data.tar.gz: 59310dd1e3791d555998cd37e042247a6c558c79699b3e0c7c8ee308c9536e9640085daa3e4df19465076aab2ea0a4532a06e6844baf1bc9943e662454355216
data/.doit/hello CHANGED
@@ -1,2 +1,3 @@
1
+ # usage just a test
1
2
  echo Hello
2
3
  pwd
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.2.3
1
+ ruby-2.2.0
data/.watchr CHANGED
@@ -17,6 +17,7 @@ end
17
17
  def run_it(type, file)
18
18
  case type
19
19
  when 'test'; run %Q{ruby -I"lib:test" -rubygems #{file}}
20
+ when 'spec'; run %Q{spring rspec -X #{file}}
20
21
  else; puts "#{H} unknown type: #{type}, file: #{file}"
21
22
  end
22
23
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doit (0.2.8)
4
+ doit (0.3.0)
5
5
  micro-optparse (~> 1)
6
6
 
7
7
  GEM
@@ -10,9 +10,9 @@ GEM
10
10
  docile (1.1.5)
11
11
  json (1.8.3)
12
12
  micro-optparse (1.2.0)
13
- minitest (5.8.3)
13
+ minitest (5.8.4)
14
14
  observr (1.0.5)
15
- rake (10.4.2)
15
+ rake (10.5.0)
16
16
  simplecov (0.11.1)
17
17
  docile (~> 1.1.0)
18
18
  json (~> 1.8)
@@ -29,6 +29,3 @@ DEPENDENCIES
29
29
  observr
30
30
  rake
31
31
  simplecov
32
-
33
- BUNDLED WITH
34
- 1.10.6
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
@@ -29,12 +33,13 @@ File Structure
29
33
  --------------
30
34
  ~/.doit/deploy # chmod +x .doit/deploy
31
35
  ~/.doit/deploy.yml
32
- $PROJ/.doit/deploy.yml # overwrites
36
+ $PROJ/.doit/deploy.yml # overwrites $HOME(~/) script/configuration
33
37
  $PROJ/.doit/push # chmod +x .doit/deploy
34
38
  $PROJ/.doit/push.yml
35
39
 
36
40
  $PROJ/.doit/push
37
41
  ----------------
42
+ #! /bin/sh
38
43
  if ! (git status | grep 'nothing to commit'); then
39
44
  echo "push: commits are pending"
40
45
  exit 1
@@ -68,4 +73,4 @@ $PROJ/.doit/push
68
73
  - bob@sample.com
69
74
  - alice@customer.com
70
75
 
71
- Copyright (c) 2014 [Dittmar Krall], released under the MIT license
76
+ Copyright (c) 2014-2016 [Dittmar Krall], released under the MIT license
data/bin/doit CHANGED
@@ -11,7 +11,8 @@ options = Parser.new do |p|
11
11
  p.banner = "Usage: doit script... [options] # execute locally or remotely"
12
12
  p.version = "doit #{Globals::VERSION}"
13
13
  p.option :list, 'Lists available scripts'
14
- p.option :remote, 'Remote host or comma separated hosts', default: '---', optional: true
14
+ p.option :each, 'Lists each remote command (no execution)'
15
+ p.option :remote, 'Remote host or comma separated hosts', default: '...', optional: true
15
16
  p.option :silent, 'Run silently; suppress output'
16
17
  p.option :verbose, 'Enable verbose output'
17
18
  p.option :noop, 'Suppress execution of commannds'
data/lib/doit.rb CHANGED
@@ -3,9 +3,10 @@ require 'run'
3
3
  require 'import'
4
4
  require 'what'
5
5
 
6
- class Doit
6
+ Doit = Object.new
7
+ class << Doit
7
8
 
8
- def self.start(options)
9
+ def start(options)
9
10
  @options = options
10
11
  list if options[:list]
11
12
 
@@ -15,11 +16,11 @@ class Doit
15
16
  execute(script) if script
16
17
  end
17
18
 
18
- def self.options
19
+ def options
19
20
  @options || {}
20
21
  end
21
22
 
22
- def self.list
23
+ def list
23
24
  hsh = Import.list
24
25
  hsh.sort.each { |abb, long|
25
26
  puts "#{abb}\t- #{long}"
@@ -33,7 +34,7 @@ class Doit
33
34
  }
34
35
  end
35
36
 
36
- def self.execute(name)
37
+ def execute(name)
37
38
  Import.init(name)
38
39
  unless Import.script
39
40
  puts "doit: script '#{name}' not found"
@@ -41,17 +42,21 @@ class Doit
41
42
  end
42
43
  What.init(Import.script, Import.config)
43
44
 
44
- where_loop
45
+ What.where.each { |w|
46
+ puts "doit #{name} -r #{w}"
47
+ } if options[:each]
48
+
49
+ where_loop unless options[:each]
45
50
  end
46
51
 
47
52
  private
48
- def self.where_loop
53
+ def where_loop
49
54
  What.where.each { |w|
50
55
  matrix_loop(w)
51
56
  }
52
57
  end
53
58
 
54
- def self.matrix_loop(w)
59
+ def matrix_loop(w)
55
60
  What.matrix.each { |mm|
56
61
  prefix = mm.empty? ? '' : "#{What.to_env(mm)}\n"
57
62
 
data/lib/globals.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Globals
2
- VERSION = '0.2.8'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/import.rb CHANGED
@@ -1,23 +1,24 @@
1
1
  require 'pathname'
2
2
  require 'erb'
3
3
 
4
- class Import
4
+ Import = Object.new
5
+ class << Import
5
6
 
6
- def self.script; @script; end
7
- def self.config; @config; end
7
+ def script; @script; end
8
+ def config; @config; end
8
9
 
9
- def self.init(name)
10
+ def init(name)
10
11
  @script = read(name)
11
12
  @config = ERB.new(read("#{name}.yml") || '').result
12
13
  info
13
14
  end
14
15
 
15
16
  # returns Hash { 'pull' => '/home/dk/.doit/pull', ... }
16
- def self.list
17
+ def list
17
18
  @list ||= list2
18
19
  end
19
20
 
20
- def self.info
21
+ def info
21
22
  return unless Doit.options[:verbose]
22
23
 
23
24
  My.verbose "SCRIPT", @script
@@ -26,7 +27,7 @@ class Import
26
27
 
27
28
 
28
29
  private
29
- def self.list2
30
+ def list2
30
31
  res = {}
31
32
  Pathname.pwd.descend { |dir|
32
33
  doit_dir = dir + '.doit'
@@ -46,11 +47,11 @@ class Import
46
47
  res
47
48
  end
48
49
 
49
- def self.read(name)
50
+ def read(name)
50
51
  try_ascend(".doit/#{name}")
51
52
  end
52
53
 
53
- def self.try_ascend(filename)
54
+ def try_ascend(filename)
54
55
  Pathname.pwd.ascend { |dir|
55
56
  str = dir + filename
56
57
  return File.read(str) if File.exists?(str)
data/lib/my.rb CHANGED
@@ -1,6 +1,7 @@
1
- class My
1
+ My = Object.new
2
+ class << My
2
3
 
3
- def self.verbose(what, txt)
4
+ def verbose(what, txt)
4
5
  marker = '*'*4
5
6
  arr = txt
6
7
  arr = txt ? txt.split("\n") : '' unless Array === txt
data/lib/run.rb CHANGED
@@ -1,8 +1,9 @@
1
- class Run
1
+ Run = Object.new
2
+ class << Run
2
3
 
3
- def self.ssh; @ssh; end
4
+ def ssh; @ssh; end
4
5
 
5
- def self.init(cmds, where)
6
+ def init(cmds, where)
6
7
  aster = '*'*24
7
8
  puts "#{aster} #{where} #{aster}"
8
9
  @ssh = nil
@@ -21,12 +22,12 @@ class Run
21
22
  @ssh = "ssh #{host}" if host
22
23
  end
23
24
 
24
- def self.info
25
+ def info
25
26
  My.verbose('SSH', @ssh)
26
27
  My.verbose('cmds', @cmds)
27
28
  end
28
29
 
29
- def self.run
30
+ def run
30
31
  here = '___EOS___'
31
32
  silent = Doit.options[:silent] ? '>/dev/null' : ''
32
33
  cmd = "cat <<'#{here}\' | #{@ssh} bash -i -l #{silent} 2>&1"
data/lib/what.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require 'yaml'
2
2
  require 'doit'
3
3
 
4
- class What
4
+ What = Object.new
5
+ class << What
5
6
 
6
- def self.matrix; @matrix; end
7
- def self.where; @where; end
8
- def self.env; @env; end
7
+ def matrix; @matrix; end
8
+ def where; @where; end
9
+ def env; @env; end
9
10
 
10
- def self.init(script, config)
11
+ def init(script, config)
11
12
  @matrix = nil
12
13
  @yml = (config && YAML.load(config)) || {}
13
14
 
@@ -28,12 +29,12 @@ class What
28
29
  info
29
30
  end
30
31
 
31
- def self.to_env(hsh)
32
+ def to_env(hsh)
32
33
  arr = hsh.collect { |key, value| "#{key.to_s.upcase}=#{value}" }
33
34
  arr.join ' '
34
35
  end
35
36
 
36
- def self.info
37
+ def info
37
38
  return unless Doit.options[:verbose]
38
39
 
39
40
  My.verbose "where", @where
@@ -43,7 +44,7 @@ class What
43
44
 
44
45
 
45
46
  private
46
- def self.build_matrix
47
+ def build_matrix
47
48
  unless @yml.empty?
48
49
  key, value = @yml.first
49
50
  @yml.delete(key)
@@ -52,7 +53,7 @@ class What
52
53
  end
53
54
  end
54
55
 
55
- def self.add_to_matrix(key, val)
56
+ def add_to_matrix(key, val)
56
57
  arr = Array === val ? val.collect {|v| [{key => v}] } : [{key => val}]
57
58
  @matrix = @matrix ? @matrix.product(arr) : arr
58
59
  end
data/test/doit_test.rb CHANGED
@@ -37,4 +37,18 @@ describe Doit do
37
37
  assert_match /not found/, out
38
38
  end
39
39
 
40
+ it "tests option --each" do
41
+ out = noop({each: true}) {
42
+ Doit.execute('hello')
43
+ }
44
+ assert_match /doit hello -r/, out
45
+ end
46
+
47
+ it "coverage: list; option -lv" do
48
+ out = noop({verbose: true, list: true}) {
49
+ Doit.start({verbose: true, list: true})
50
+ }
51
+ assert_match /just a test\n/, out
52
+ end
53
+
40
54
  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.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: micro-optparse
@@ -33,7 +33,6 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".doit/hello"
35
35
  - ".doit/hello.yml"
36
- - ".ruby-gemset"
37
36
  - ".ruby-version"
38
37
  - ".travis.yml"
39
38
  - ".watchr"
@@ -76,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
75
  version: '0'
77
76
  requirements: []
78
77
  rubyforge_project:
79
- rubygems_version: 2.4.2
78
+ rubygems_version: 2.4.5
80
79
  signing_key:
81
80
  specification_version: 4
82
81
  summary: Simple local & remote script executor
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- rails-4.2