ro_thor 4.5.6 → 4.6.5

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
  SHA256:
3
- metadata.gz: 1b67dc9bd9932eeb51d0f0831054f1dd0ac75b363680a83be38b261fbdfa69e9
4
- data.tar.gz: 2ae3bb147c2da61d5ec4b9703d0ba5f2d4b565756b643797b8e7332885418bba
3
+ metadata.gz: cbeb5aef6502717a385722f30e59461061ac1d95d436ccf65c688310d7e244ed
4
+ data.tar.gz: 65414774e137c2b63f8e9c2784fe8f5820b6b0187b54fcd9d7b2dca45743eb4d
5
5
  SHA512:
6
- metadata.gz: 98b778674d80cb95f87c1f477491a34789bead212e9ed5c1e16ec4f899e9a1fd1b6ca91358198bcd367503fe300a25e30afc4b76e583d215b1f1fec6ca3031bf
7
- data.tar.gz: '078d536d5861d011906eef2f69083145ea441d738c207a855dfccc4c80a565f98bf9c9935fffddcc29d4331d6e33c363b279c66204d42051a2950c59e19d0f30'
6
+ metadata.gz: 83e55c0ded31663342d322067dd74311b61a9d7e21d7950af71970e61ee4641e93ea05f3791b5bb5d94c245a1f7437a44ff23d0dc9a14c1edaa98225d487985d
7
+ data.tar.gz: 0764d49c5abf5e442ebe7be280dd116609d525d861c6c1bd61e61fb549386b97afe0d5627a238c445e55b93b60d17b75ae562e7ce13e53cfde36b1b4b810be95
@@ -1,11 +1,13 @@
1
1
  require 'pathname'
2
2
  $LOAD_PATH.unshift(Pathname.new(__FILE__).parent.to_s)
3
+ require 'shellwords'
3
4
  require 'thor'
4
5
  require 'open3'
5
6
  require 'ro_thor/base'
6
7
  require 'ro_thor/sh'
7
8
  require 'ro_thor/ro_file'
8
9
  require 'ro_thor/array'
10
+ require 'ro_thor/string'
9
11
  require 'ro_thor/helper'
10
12
  require 'ro_thor/ro_err'
11
13
  require 'ro_thor/http'
@@ -38,6 +40,14 @@ class RoThor < Thor
38
40
  desc(str, "")
39
41
  end
40
42
 
43
+ def st(*args)
44
+ start(*args)
45
+ end
46
+
47
+ def start(*args)
48
+ super(args)
49
+ end
50
+
41
51
  def create_command(*args, &blk)
42
52
  if @usage.nil?
43
53
  return
@@ -45,16 +55,12 @@ class RoThor < Thor
45
55
  super
46
56
  end
47
57
 
48
- def st(*args, &blk)
49
- start(args)
50
- end
51
-
52
58
  def lamb(*args, &blk)
53
59
  lambda(*args, &blk)
54
60
  end
55
61
  end
56
62
 
57
- def open_url(url, user_data_dir=nil, *args, &blk)
63
+ def open_url(url, user_data_dir = nil, *args, &blk)
58
64
  user_data_dir ||= "#{ENV['HOME']}/.config/google-chrome"
59
65
  sys %Q(google-chrome --user-data-dir=#{user_data_dir.strip} "#{url}")
60
66
  end
@@ -63,6 +69,10 @@ class RoThor < Thor
63
69
  RoFile.basename(Dir.pwd)
64
70
  end
65
71
 
72
+ def sh_esc(str)
73
+ Shellwords.escape(str)
74
+ end
75
+
66
76
  def cur_pj_name2(*args, &blk)
67
77
  cur_pj_name.gsub(%r{^ro_}, "")
68
78
  end
@@ -76,7 +86,6 @@ class RoThor < Thor
76
86
  end
77
87
 
78
88
 
79
-
80
89
  def down_d(*args, &blk)
81
90
  RoFile.join("/media/roroco/disk750/Downloads", *args, &blk)
82
91
  end
@@ -136,17 +145,16 @@ class RoThor < Thor
136
145
 
137
146
  def toggle_win(win_name)
138
147
  wins = begin
139
- shsu("xdotool search --onlyvisible #{win_name}").split("\n")
140
- rescue RoThor::Sh::Err => e
141
- out(e)
142
- out(e.backtrace.join("\n"))
143
- sleep(0.5)
144
- retry
145
- end
148
+ shsu("xdotool search --onlyvisible #{win_name}").split("\n")
149
+ rescue RoThor::Sh::Err => e
150
+ out(e)
151
+ out(e.backtrace.join("\n"))
152
+ sleep(0.5)
153
+ retry
154
+ end
146
155
  if wins.size > 0
147
156
  sh "xdotool windowactivate #{wins.first.strip}"
148
157
  end
149
158
  end
150
-
151
159
  end
152
160
 
@@ -1,6 +1,7 @@
1
1
  require_relative 'base'
2
2
  class Array
3
3
  unless method_defined? :ro_opts
4
+ # @return [] return args_without_options, options
4
5
  def ro_opts(*args, &blk)
5
6
  a = []
6
7
  opts = {}
@@ -1,4 +1,5 @@
1
1
  require_relative 'base'
2
+ require_relative 'string'
2
3
 
3
4
  class RoThor
4
5
  module Helper
@@ -11,8 +12,8 @@ class RoThor
11
12
  shsu("xclip -sel clip -o")
12
13
  end
13
14
 
14
- def to_md5(s, *args, &blk)
15
- Digest::MD5.hexdigest(s)
15
+ def to_md5(str)
16
+ str.md5
16
17
  end
17
18
 
18
19
  def in_pj(pj_name, *args, &blk)
@@ -16,6 +16,11 @@ class RoThor
16
16
  end
17
17
  end
18
18
 
19
+ def head(url, *args, &blk)
20
+ out "head #{url}"
21
+ h.head(url, *args, &blk)
22
+ end
23
+
19
24
  def get(url, *args, &blk)
20
25
  out "get #{url}"
21
26
  h.get(url, *args, &blk)
@@ -42,7 +42,9 @@ class RoThor
42
42
 
43
43
  def msp(f, *args, &blk)
44
44
  p = parent(f)
45
- FileUtils.mkpath(p)
45
+ if !test(?d, p)
46
+ FileUtils.mkpath(p)
47
+ end
46
48
  end
47
49
 
48
50
  def msd(p, *args, &blk)
@@ -4,6 +4,7 @@ require 'net/ssh'
4
4
  require_relative 'helper'
5
5
  require_relative 'sh'
6
6
  require_relative 'ro_file'
7
+ require 'term/ansicolor'
7
8
 
8
9
  class RoThor
9
10
  class SSH
@@ -42,7 +43,7 @@ class RoThor
42
43
 
43
44
  ch = se.open_channel do |ch|
44
45
  ch.exec(cmd) do |ch, success|
45
- unless success
46
+ if !success
46
47
  raise ::RoErr::RmtErr, "could not exe cmd: #{command.inspect}"
47
48
  end
48
49
 
@@ -74,12 +75,14 @@ class RoThor
74
75
  ch.wait
75
76
  ch.close
76
77
 
78
+ stdout = out_a.join('')
79
+
77
80
  stderr_lines = stderr_lines.hits
78
81
  stderr_lines.delete_if do |l|
79
82
  l.match(%r{^/.*warning\:.*$})
80
83
  end
81
84
 
82
- unless stderr_lines.empty?
85
+ if !stderr_lines.empty?
83
86
  if stderr_lines.any? do |l|
84
87
  l.match(%r{\tfrom})
85
88
  end
@@ -95,19 +98,21 @@ class RoThor
95
98
  end
96
99
  end
97
100
 
98
- e = RoErr::RmtErr.new(uncol(err_msg_arr.join), backtrace: bt.map(&:strip).hits)
101
+ e = RoErr::RmtErr.new(stdout + uncol(err_msg_arr.join))
102
+ e.set_backtrace(bt.map(&:strip).hits)
99
103
  else
100
- e = RoErr::RmtErr.new(uncol(stderr_lines.join("\n")), backtrace: clr)
104
+ e = RoErr::RmtErr.new(stdout + uncol(stderr_lines.join("\n")))
105
+ e.set_backtrace(clr)
101
106
  end
102
107
 
103
- if ::RoCell::Rmt.ignore_err
104
- out_ins.warn e
105
- else
106
- raise e
107
- end
108
+ # if ::RoCell::Rmt.ignore_err
109
+ # out_ins.warn e
110
+ # else
111
+ raise e
112
+ # end
108
113
  end
109
114
 
110
- out_a.join('')
115
+ stdout
111
116
  end
112
117
 
113
118
  def uncol(*args, &blk)
@@ -0,0 +1,7 @@
1
+ class String
2
+ if !method_defined? :md5
3
+ def md5
4
+ Digest::MD5.hexdigest(self)
5
+ end
6
+ end
7
+ end
@@ -2,8 +2,24 @@ require 'rails_helper'
2
2
  require 'ro_thor/ssh'
3
3
 
4
4
  describe 'RoThor::Rmt.new' do
5
- it :sh do
6
- s = RoThor::SSH.new('root@me')
7
- s.sh('ls;ls')
5
+ describe "sh" do
6
+ it "1" do
7
+ s = RoThor::SSH.new('root@techprpr')
8
+ s.sh('ls;ls')
9
+ end
10
+
11
+ it "capture err" do
12
+ s = RoThor::SSH.new("root@techprpr")
13
+ begin
14
+ # raise "err"
15
+ s.sh("lrekljeklwjl")
16
+ rescue Exception => e
17
+ puts "e:#{e} ---- #{File.basename __FILE__}:#{__LINE__}"
18
+ end
19
+ end
20
+ end
21
+
22
+ it "sh with regex" do
23
+
8
24
  end
9
25
  end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ class C < RoThor
4
+ usg :todo
5
+
6
+ def todo(*args)
7
+
8
+ end
9
+ end
10
+
11
+ describe 'RoThor' do
12
+ it "1" do
13
+ C.start(*['todo', 'arg1', "arg2"])
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro_thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.6
4
+ version: 4.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-01 00:00:00.000000000 Z
11
+ date: 2020-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -110,10 +110,12 @@ files:
110
110
  - lib/ro_thor/ro_file.rb
111
111
  - lib/ro_thor/sh.rb
112
112
  - lib/ro_thor/ssh.rb
113
+ - lib/ro_thor/string.rb
113
114
  - spec/lib/core_ext/array_spec.rb
114
115
  - spec/lib/ro_cmd/thor/dp_spec.rb
115
116
  - spec/lib/ro_thor/ro_err_spec.rb
116
117
  - spec/lib/ro_thor/ssh_spec.rb
118
+ - spec/lib/ro_thor_spec.rb
117
119
  - spec/mysql/my.cnf
118
120
  - spec/rails_helper.rb
119
121
  - spec/spec_helper.rb
@@ -140,10 +142,11 @@ signing_key:
140
142
  specification_version: 4
141
143
  summary: ''
142
144
  test_files:
143
- - spec/spec_helper.rb
145
+ - spec/lib/ro_thor_spec.rb
144
146
  - spec/lib/ro_cmd/thor/dp_spec.rb
145
- - spec/lib/core_ext/array_spec.rb
146
147
  - spec/lib/ro_thor/ssh_spec.rb
147
148
  - spec/lib/ro_thor/ro_err_spec.rb
149
+ - spec/lib/core_ext/array_spec.rb
148
150
  - spec/rails_helper.rb
151
+ - spec/spec_helper.rb
149
152
  - spec/mysql/my.cnf