squared 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60e2da1ce8ec4439d4180db0c0f806d9984046ef5f12b34008563edd7b40b938
4
- data.tar.gz: 6eb7ef1c8273d10747cb79c1a113dae53210cebd167969f4a1546a9fc07162f0
3
+ metadata.gz: 45b563863fb21461ec7c629dc01a197485c15c8a26239db170a91970a6cade9a
4
+ data.tar.gz: f7051ae9101dbced194185f5731c6bd028ccd3e56dfbbab047a7370c220412de
5
5
  SHA512:
6
- metadata.gz: 75f989753670bd5854a8dccc6a3bf8d3d7397d2a373a50d46eaa7add861ff8d1f24cffb1c9ac00d48756d89abb50728c35368beb62649b3d704f3d7b059b449a
7
- data.tar.gz: 6387222860eb65bd57cd14ba86b77b39d47a64d5a03940a5b6f6ac0ccea6368f0ab8df0a1886d5f6e6eec83f89887397b72f57a647a4ad06efa632020c1a5938
6
+ metadata.gz: 74adde082a170b07b65ccc258b94681826c9fdbda9120a39128f9236d4215c904a7dac32451428e92cdfbabd354e6dce810447df03660169b34783d02a808978
7
+ data.tar.gz: c50ee1d27e5be607e84fd82bd4d15e4d3ec8e4d12acd4619ef1421d2206e313205e8aaf849965e6140d6e5873848001d2c55d00f0335f8274ef6c95213ec7990
data/README.ruby.md CHANGED
@@ -6,12 +6,12 @@
6
6
 
7
7
  ## Prerequisites
8
8
 
9
- * Ruby 2.4+
9
+ * Ruby 2.4
10
10
 
11
11
  ### Optional
12
12
 
13
13
  * [Repo](https://source.android.com/docs/setup/reference/repo)
14
- * Python 3.6+
14
+ * Python 3.6
15
15
 
16
16
  ```sh
17
17
  mkdir -p ~/.bin
@@ -40,9 +40,10 @@ require "squared/workspace/repo" # Repo (optional)
40
40
 
41
41
  Workspace::Application
42
42
  .new("squared") # REPO_HOME
43
- .repo("https://github.com/anpham6/squared-repo", "nightly", run: "build") # Repo (optional)
43
+ .repo("https://github.com/anpham6/squared-repo", "nightly", run: "build", ref: :node) # Repo (optional)
44
44
  .run("rake install", ref: :ruby)
45
- .clean("rake clean", group: "default") # depend test doc
45
+ .depend(false, group: "default")
46
+ .clean("rake clean", group: "default")
46
47
  .clean(["build/"], group: "app")
47
48
  .add("pathname", run: "rake compile", copy: "rake install", test: "rake test", group: "default", ref: :ruby) # Ruby (with C extensions)
48
49
  .add("optparse", doc: "rake rdoc", group: "default") # Uses bundler/gem_tasks (without C extensions)
@@ -55,8 +56,10 @@ Workspace::Application
55
56
  .build(default: "status", parallel: ["pull", "fetch", "rebase", "copy", "clean"]) do |workspace|
56
57
  workspace
57
58
  .enable_aixterm
58
- .style(:banner, "bright_cyan", "bold", "bright_black!")
59
- .finalize! # Optional
59
+ .style({
60
+ banner: ["bright_cyan", "bold", "bright_black!"],
61
+ border: "bright_white"
62
+ })
60
63
  end
61
64
  # pathname = /workspaces/pathname
62
65
  # optparse = /workspaces/optparse
@@ -66,9 +69,11 @@ Workspace::Application
66
69
  # pir = /workspaces/pi-r
67
70
  # squared = /workspaces/squared
68
71
 
69
- Repo::Workspace
72
+ Workspace::Application
70
73
  .new("squared")
71
- .group("default", "ruby", run: "rake build", copy: "rake install", clean: "rake clean", pathname: { run: "rake compile" })
74
+ .group("default", "ruby", run: "rake build", copy: "rake install", clean: "rake clean", override: {
75
+ pathname: { run: "rake compile" }
76
+ })
72
77
  .build
73
78
  # default = /workspaces/ruby/*
74
79
  # pathname = /workspaces/ruby/pathname
@@ -93,6 +98,7 @@ rake pull:node # emc + pir + squared
93
98
 
94
99
  rake build # All except "android"
95
100
  rake doc # optparse + android
101
+ rake depend # All except "default"
96
102
 
97
103
  rake build:ruby # rake compile + rake install + rake install
98
104
 
@@ -103,6 +109,22 @@ rake clean:app # none + skip + ["build/"]
103
109
  rake clean:node # none + ["publish/**/*.js", "tmp/"] + ["build/"]
104
110
  ```
105
111
 
112
+ ## Commands
113
+
114
+ * run
115
+ * depend
116
+ * test
117
+ * doc
118
+ * clean
119
+
120
+ ## Styles
121
+
122
+ * banner
123
+ * border
124
+ * header
125
+ * active
126
+ * inline
127
+
106
128
  ## LICENSE
107
129
 
108
130
  BSD 3-Clause
@@ -23,7 +23,11 @@ module Squared
23
23
  white!: '47'
24
24
  },
25
25
  theme: {
26
- workspace: {},
26
+ workspace: {
27
+ header: %i[bold],
28
+ active: %i[bold],
29
+ inline: %i[bold]
30
+ },
27
31
  project: {},
28
32
  viewer: {
29
33
  banner: %i[blue bold],
@@ -59,7 +63,15 @@ module Squared
59
63
  VAR[key.is_a?(::String) ? key.to_sym : key] = val
60
64
  end
61
65
 
62
- def env(key, equals: nil, ignore: nil, default: nil, **)
66
+ def __freeze__
67
+ VAR.each_value(&:freeze)
68
+ VAR[:theme].each_value(&:freeze)
69
+ VAR.freeze
70
+ end
71
+
72
+ module_function
73
+
74
+ def env(key, default = nil, equals: nil, ignore: nil, **)
63
75
  ret = ENV.fetch(key, '')
64
76
  return ret == equals.to_s unless equals.nil?
65
77
 
@@ -81,11 +93,5 @@ module Squared
81
93
  obj
82
94
  end
83
95
  end
84
-
85
- def finalize!
86
- VAR.each_value(&:freeze)
87
- VAR[:theme].each_value(&:freeze)
88
- VAR.freeze
89
- end
90
96
  end
91
97
  end
@@ -15,10 +15,14 @@ module Squared
15
15
  end
16
16
 
17
17
  def done
18
- ret = to_a.map!(&:to_s).reject(&:empty?).join(@delim)
18
+ ret = to_s
19
19
  clear
20
20
  ret
21
21
  end
22
+
23
+ def to_s
24
+ to_a.map!(&:to_s).reject(&:empty?).join(@delim)
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -39,46 +39,8 @@ module Squared
39
39
 
40
40
  private
41
41
 
42
- def emphasize(val, title: nil, cols: nil, sub: nil, pipe: nil)
43
- n = 0
44
- if title
45
- title = title.to_s
46
- n = title.size
47
- end
48
- if val.is_a?(::Array)
49
- lines = val
50
- else
51
- lines = val.to_s.lines.map(&:chomp)
52
- lines[0] = "#{val.class}: #{lines.first}" if (err = val.is_a?(::StandardError))
53
- end
54
- n = cols || [n, lines.max_by(&:size).size].max
55
- if $stdout.tty?
56
- require 'io/console'
57
- (n = [n, $stdout.winsize[1] - 4].min) rescue nil
58
- end
59
- out = []
60
- bord = '-' * (n + 4)
61
- sub = as_a(sub)
62
- pr = lambda do |line|
63
- s = line.ljust(n)
64
- sub.each { |h| s = sub_style(s, **h) }
65
- "| #{s} |"
66
- end
67
- out << bord
68
- out.push(pr.(title), bord) if title
69
- lines.each { |line| out << pr.(line) }
70
- out << bord
71
- if block_given?
72
- yield out
73
- elsif pipe.respond_to?(:puts)
74
- pipe.puts out
75
- else
76
- err ? warn(out) : puts(out)
77
- end
78
- end
79
-
80
42
  def sub_style(val, *args, styles: nil, pat: nil, index: 1)
81
- return val unless ENV['NO_COLOR'].to_s.empty?
43
+ return val unless ENV.fetch('NO_COLOR', '').empty? && !__get__(:no_color)
82
44
 
83
45
  if pat && index != 0
84
46
  return val unless (data = pat.match(val))
@@ -158,11 +120,12 @@ module Squared
158
120
  ret << "-0.#{b}".to_f unless b.to_i > 255
159
121
  end
160
122
  end
161
- !empty && ret.empty? ? nil : ret
123
+ ret if empty || !ret.empty?
162
124
  end
163
125
 
164
126
  def apply_style(data, key, *args, empty: true)
165
- return unless !data.is_a?(Symbol) || (data = __get__(:theme)[data])
127
+ data = __get__(:theme)[data] if data.is_a?(Symbol)
128
+ return unless data
166
129
 
167
130
  set = ->(k, v) { data[k.to_sym] = check_style(v, empty: empty) }
168
131
  if key.is_a?(Hash)
@@ -172,10 +135,6 @@ module Squared
172
135
  end
173
136
  end
174
137
 
175
- def raise_error(*args, hint: nil, kind: ArgumentError)
176
- raise kind, message(*args, hint: hint)
177
- end
178
-
179
138
  def log_title(level, color: true)
180
139
  level = if level.is_a?(::Numeric)
181
140
  case level
@@ -209,6 +168,50 @@ module Squared
209
168
  msg << (color ? sub_style(subject, :underline) : subject) if subject
210
169
  message(msg.join(' '), *args, hint: hint)
211
170
  end
171
+
172
+ def raise_error(*args, hint: nil, kind: ArgumentError)
173
+ raise kind, message(*args, hint: hint)
174
+ end
175
+
176
+ module_function
177
+
178
+ def emphasize(val, title: nil, cols: nil, sub: nil, pipe: nil)
179
+ n = 0
180
+ if title
181
+ title = title.to_s
182
+ n = title.size
183
+ end
184
+ if val.is_a?(::Array)
185
+ lines = val
186
+ else
187
+ lines = val.to_s.lines.map(&:chomp)
188
+ lines[0] = "#{val.class}: #{lines.first}" if (err = val.is_a?(::StandardError))
189
+ end
190
+ n = cols || [n, lines.max_by(&:size).size].max
191
+ if $stdout.tty?
192
+ require 'io/console'
193
+ (n = [n, $stdout.winsize[1] - 4].min) rescue nil
194
+ end
195
+ out = []
196
+ bord = '-' * (n + 4)
197
+ sub = [sub] if sub && !sub.is_a?(::Array)
198
+ pr = lambda do |line|
199
+ s = line.ljust(n)
200
+ sub&.each { |h| s = sub_style(s, **h) }
201
+ "| #{s} |"
202
+ end
203
+ out << bord
204
+ out.push(pr.(title), bord) if title
205
+ lines.each { |line| out << pr.(line) }
206
+ out << bord
207
+ if block_given?
208
+ yield out
209
+ elsif pipe.respond_to?(:puts)
210
+ pipe.puts out
211
+ else
212
+ err ? warn(out) : puts(out)
213
+ end
214
+ end
212
215
  end
213
216
  end
214
217
  end
@@ -6,12 +6,12 @@ require 'rake'
6
6
  module Squared
7
7
  module Common
8
8
  module Shell
9
- private
9
+ module_function
10
10
 
11
11
  def shell_escape(val, quote: false)
12
- return (quote ? shell_quote(val, force: false) : val) if ::Rake::Win32.windows?
12
+ return Shellwords.escape(val) unless ::Rake::Win32.windows?
13
13
 
14
- Shellwords.escape(val)
14
+ quote ? shell_quote(val, force: false) : val
15
15
  end
16
16
 
17
17
  def shell_quote(val, force: true)
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  module Squared
7
7
  module Common
8
8
  module System
9
- private
9
+ module_function
10
10
 
11
11
  def shell(*cmd, **kwargs)
12
12
  if RUBY_VERSION =~ /^2\.[0-5]\./
@@ -20,13 +20,44 @@ module Squared
20
20
  end
21
21
  end
22
22
 
23
+ def confirm(msg, agree: 'Y', cancel: 'N', default: nil, attempts: 5, timeout: 15)
24
+ require 'readline'
25
+ require 'timeout'
26
+ agree = /^#{agree}$/i if agree.is_a?(String)
27
+ cancel = /^#{cancel}$/i if cancel.is_a?(String)
28
+ Timeout.timeout(timeout) do
29
+ begin
30
+ while (ch = Readline.readline(msg, true))
31
+ ch = ch.chomp
32
+ ch = default if ch.empty?
33
+ case ch
34
+ when agree
35
+ return true
36
+ when cancel
37
+ return false
38
+ end
39
+ attempts -= 1
40
+ exit 1 unless attempts >= 0
41
+ end
42
+ rescue Interrupt
43
+ puts
44
+ exit 0
45
+ else
46
+ false
47
+ end
48
+ end
49
+ end
50
+
23
51
  def copy_d(src, dest, glob: ['**/*'], create: false, verbose: true)
52
+ src = Pathname.new(src)
53
+ dest = Pathname.new(dest)
24
54
  raise "#{dest} (not found)" if !create && !dest.exist?
25
55
 
26
56
  subdir = []
27
57
  files = 0
28
58
  dest.mkpath if create
29
- as_a(glob).each do |val|
59
+ glob = [glob] unless glob.is_a?(::Array)
60
+ glob.each do |val|
30
61
  Dir.glob(src.join(val)) do |path|
31
62
  ent = Pathname.new(path)
32
63
  next if ent.directory?
@@ -48,7 +79,8 @@ module Squared
48
79
  if !overwrite
49
80
  path = Pathname.new(dest)
50
81
  if path.directory?
51
- src = as_a(src).reject { |val| path.join(File.basename(val)).exist? }
82
+ src = [src] unless src.is_a?(::Array)
83
+ src = src.reject { |val| path.join(File.basename(val)).exist? }
52
84
  elsif path.exist?
53
85
  return
54
86
  end
@@ -5,15 +5,7 @@ require 'rake'
5
5
  module Squared
6
6
  module Common
7
7
  module Task
8
- private
9
-
10
- def collect_args(args, *keys)
11
- ret = []
12
- return ret unless args.is_a?(::Rake::TaskArguments)
13
-
14
- keys.each { |key| ret << args.fetch(key) if args.key?(key) }
15
- ret += args.extras
16
- end
8
+ module_function
17
9
 
18
10
  def invoke(name, *args, exception: true)
19
11
  ::Rake::Task[name].invoke(*args)
@@ -9,7 +9,6 @@ module Squared
9
9
  class Viewer
10
10
  include Common
11
11
  include Format
12
- include Task
13
12
  include ::Rake::DSL
14
13
 
15
14
  class << self
@@ -52,7 +51,7 @@ module Squared
52
51
  @required = true
53
52
  project ? [project, 'not found'] : %w[name missing]
54
53
  end
55
- warn log_message(:warn, msg, subject: self.class, hint: hint, color: !pipe?)
54
+ warn log_message(:warn, msg, subject: self.class, hint: hint)
56
55
  end
57
56
 
58
57
  def build
@@ -97,7 +96,7 @@ module Squared
97
96
  namespace command do
98
97
  task type, [:keys] do |_, args|
99
98
  if file
100
- read_keys(obj, type, file.to_s, collect_args(args, :keys), ext: ext)
99
+ read_keys(obj, type, file.to_s, args.to_a, ext: ext)
101
100
  else
102
101
  read_keys(obj, type, args.keys, args.extras, ext: ext)
103
102
  end
@@ -188,7 +187,7 @@ module Squared
188
187
  title = Pathname.new(file)
189
188
  .realpath
190
189
  .to_s
191
- .sub(/^#{Regexp.escape(Dir.pwd + ::File::SEPARATOR)}/, '')
190
+ .sub(Regexp.new("^#{Regexp.escape(File.join(Dir.pwd, ''))}"), '')
192
191
  sub = if pipe?
193
192
  nil
194
193
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end