squared 0.4.6 → 0.4.8
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 +4 -4
- data/CHANGELOG.md +77 -0
- data/README.ruby.md +52 -32
- data/lib/squared/common/base.rb +1 -0
- data/lib/squared/common/class.rb +20 -5
- data/lib/squared/common/format.rb +30 -22
- data/lib/squared/common/prompt.rb +39 -1
- data/lib/squared/common/shell.rb +14 -10
- data/lib/squared/common/system.rb +3 -3
- data/lib/squared/common/utils.rb +17 -10
- data/lib/squared/config.rb +1 -2
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +39 -23
- data/lib/squared/workspace/project/base.rb +242 -243
- data/lib/squared/workspace/project/docker.rb +119 -72
- data/lib/squared/workspace/project/git.rb +252 -214
- data/lib/squared/workspace/project/node.rb +65 -67
- data/lib/squared/workspace/project/python.rb +69 -57
- data/lib/squared/workspace/project/ruby.rb +297 -98
- data/lib/squared/workspace/project/support/class.rb +199 -0
- data/lib/squared/workspace/project/support.rb +3 -0
- data/lib/squared/workspace/project.rb +1 -0
- data/lib/squared/workspace/repo.rb +6 -8
- data/lib/squared/workspace/series.rb +7 -6
- data/lib/squared/workspace.rb +1 -8
- metadata +3 -1
@@ -0,0 +1,199 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Squared
|
6
|
+
module Workspace
|
7
|
+
module Project
|
8
|
+
module Support
|
9
|
+
class OptionPartition
|
10
|
+
include Common::Shell
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
class << self
|
14
|
+
include Common::Format
|
15
|
+
include Shell
|
16
|
+
include Prompt
|
17
|
+
|
18
|
+
def append(target, *args, delim: false, escape: false, quote: true)
|
19
|
+
return if (ret = args.flatten).empty?
|
20
|
+
|
21
|
+
target << '--' if delim && !target.include?('--')
|
22
|
+
ret.map! { |val| escape ? shell_escape(val, quote: quote) : shell_quote(val) } if escape || quote
|
23
|
+
if target.is_a?(Set)
|
24
|
+
target.merge(ret)
|
25
|
+
else
|
26
|
+
target.concat(ret)
|
27
|
+
end
|
28
|
+
ret
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear(target, opts, pass: true, styles: nil, **kwargs)
|
32
|
+
return if opts.empty?
|
33
|
+
|
34
|
+
kwargs[:subject] ||= stripext(target.first)
|
35
|
+
kwargs[:hint] ||= 'unrecognized'
|
36
|
+
append(target, opts, delim: true) if kwargs.delete(:append)
|
37
|
+
warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
|
38
|
+
return if pass || confirm("Run? [#{sub_style(target, styles: styles)}] [y/N] ", 'N', timeout: 30)
|
39
|
+
|
40
|
+
raise_error 'user cancelled'
|
41
|
+
end
|
42
|
+
|
43
|
+
def arg?(target, *args, value: false)
|
44
|
+
r, s = args.partition { |val| val.is_a?(Regexp) }
|
45
|
+
unless s.empty?
|
46
|
+
s.map! { |val| Regexp.escape(shell_option(val)) }
|
47
|
+
r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
|
48
|
+
end
|
49
|
+
target.any? { |opt| r.any? { |val| opt.match?(val) } }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_reader :target, :extras, :found, :errors, :values, :project, :path
|
54
|
+
|
55
|
+
def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
|
56
|
+
:merge, :delete, :delete?, :grep, :inspect, :to_a, :to_s
|
57
|
+
def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :first, :last, :shift, :pop, :push,
|
58
|
+
:join, :map, :map!, :dup, :size
|
59
|
+
|
60
|
+
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
61
|
+
@target = target.is_a?(Set) ? target : Set.new(target)
|
62
|
+
@project = project
|
63
|
+
@path = path || project&.path
|
64
|
+
@errors = []
|
65
|
+
@found = []
|
66
|
+
parse(list, opts, **kwargs, &blk)
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse(list, opts = extras, no: nil, single: nil, args: false, first: false, pass: ['='], &blk)
|
70
|
+
@extras = []
|
71
|
+
@values = []
|
72
|
+
bare = []
|
73
|
+
e = []
|
74
|
+
b = []
|
75
|
+
m = []
|
76
|
+
p = []
|
77
|
+
q = []
|
78
|
+
qq = []
|
79
|
+
i = []
|
80
|
+
f = []
|
81
|
+
si = []
|
82
|
+
list.map do |val|
|
83
|
+
x, y = val.split('|')
|
84
|
+
if y
|
85
|
+
if (n = val.index('='))
|
86
|
+
x += val[n..-1]
|
87
|
+
end
|
88
|
+
[x, y]
|
89
|
+
else
|
90
|
+
x
|
91
|
+
end
|
92
|
+
end
|
93
|
+
.flatten
|
94
|
+
.each do |val|
|
95
|
+
if (n = val.index('='))
|
96
|
+
flag = val[0, n]
|
97
|
+
case val[n + 1]
|
98
|
+
when 'e'
|
99
|
+
e << flag
|
100
|
+
when 'b'
|
101
|
+
b << flag
|
102
|
+
when 'm'
|
103
|
+
m << flag
|
104
|
+
when 'q'
|
105
|
+
qq << flag if val[n + 2] == 'q'
|
106
|
+
q << flag
|
107
|
+
when 'p'
|
108
|
+
p << flag
|
109
|
+
when 'i'
|
110
|
+
i << flag
|
111
|
+
when 'f'
|
112
|
+
f << flag
|
113
|
+
when 'n'
|
114
|
+
si << flag
|
115
|
+
when 'v'
|
116
|
+
@values << Regexp.escape(flag)
|
117
|
+
else
|
118
|
+
next
|
119
|
+
end
|
120
|
+
m << flag if val[n + 2] == 'm'
|
121
|
+
bare << flag if val.end_with?('?')
|
122
|
+
else
|
123
|
+
bare << val
|
124
|
+
end
|
125
|
+
end
|
126
|
+
no = (no || []).map { |val| (n = val.index('=')) ? val[0, n] : val }
|
127
|
+
bare.concat(no)
|
128
|
+
skip = false
|
129
|
+
opts.each do |opt|
|
130
|
+
next @extras << opt if skip
|
131
|
+
|
132
|
+
if single&.match?(opt)
|
133
|
+
target << "-#{opt}"
|
134
|
+
elsif bare.include?(opt)
|
135
|
+
target << (opt.size == 1 ? "-#{opt}" : "--#{opt}")
|
136
|
+
elsif opt.start_with?('no-') && no.include?(name = opt[3..-1])
|
137
|
+
target << "--no-#{name}"
|
138
|
+
else
|
139
|
+
if opt =~ /\A([^=]+)=(.+)\z/
|
140
|
+
key = $1
|
141
|
+
val = $2
|
142
|
+
merge = m.include?(key)
|
143
|
+
r = ->(flag, pat) { flag.include?(key) && pat.match?(val) }
|
144
|
+
if e.include?(key)
|
145
|
+
target << shell_option(key, val, merge: merge)
|
146
|
+
elsif q.include?(key)
|
147
|
+
target << quote_option(key, val, double: qq.include?(key), merge: merge)
|
148
|
+
elsif p.include?(key) && path
|
149
|
+
target << quote_option(key, path.join(val), merge: merge)
|
150
|
+
elsif b.include?(key) || r.call(i, /^\d+$/) || r.call(f, /^\d*(?:\.\d+)?$/) || r.call(si, /^-?\d+$/)
|
151
|
+
target << basic_option(key, val, merge: merge)
|
152
|
+
elsif merge
|
153
|
+
target << basic_option(key, val, merge: true)
|
154
|
+
else
|
155
|
+
@extras << opt
|
156
|
+
end
|
157
|
+
opt = key
|
158
|
+
else
|
159
|
+
@extras << opt
|
160
|
+
skip = true if args
|
161
|
+
end
|
162
|
+
skip = true if first && pass.none? { |s| opt.include?(s) }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
@values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})=(.+)\z/
|
166
|
+
@extras.each_with_index(&blk) if block_given?
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
def swap(opts = nil)
|
171
|
+
unless opts
|
172
|
+
opts = found
|
173
|
+
@found = []
|
174
|
+
end
|
175
|
+
@extras = opts
|
176
|
+
self
|
177
|
+
end
|
178
|
+
|
179
|
+
def append(*args, **kwargs)
|
180
|
+
OptionPartition.append(target, *(args.empty? ? extras : args), **kwargs)
|
181
|
+
self
|
182
|
+
end
|
183
|
+
|
184
|
+
def clear(opts = nil, **kwargs)
|
185
|
+
opts ||= (kwargs[:errors] ? errors : extras)
|
186
|
+
styles = project.theme[:inline] if project
|
187
|
+
OptionPartition.clear(target, opts.reject { |val| found.include?(val) }, styles: styles, **kwargs)
|
188
|
+
opts.clear
|
189
|
+
self
|
190
|
+
end
|
191
|
+
|
192
|
+
def arg?(*args, **kwargs)
|
193
|
+
OptionPartition.arg?(target, *args, **kwargs)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -3,8 +3,6 @@
|
|
3
3
|
module Squared
|
4
4
|
module Workspace
|
5
5
|
module Repo
|
6
|
-
include Common::Format
|
7
|
-
|
8
6
|
class << self
|
9
7
|
def read_manifest(path)
|
10
8
|
require 'rexml/document'
|
@@ -149,9 +147,9 @@ module Squared
|
|
149
147
|
end
|
150
148
|
end
|
151
149
|
|
152
|
-
desc.('all[{0}]')
|
150
|
+
desc.call('all[{0}]')
|
153
151
|
task 'all', [:opts] do |_, args|
|
154
|
-
parse_opts.(args)
|
152
|
+
parse_opts.call(args)
|
155
153
|
stage ||= 'all'
|
156
154
|
repo['sync'].invoke
|
157
155
|
next if env('REPO_DRYRUN', equals: '2')
|
@@ -174,21 +172,21 @@ module Squared
|
|
174
172
|
end
|
175
173
|
end
|
176
174
|
|
177
|
-
desc.("init[manifest?=#{target},{0}]", target)
|
175
|
+
desc.call("init[manifest?=#{target},{0}]", target)
|
178
176
|
task 'init', [:manifest, :opts] do |_, args|
|
179
|
-
parse_opts.(args)
|
177
|
+
parse_opts.call(args)
|
180
178
|
stage = 'init'
|
181
179
|
puts if newline
|
182
180
|
system("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml", chdir: root)
|
183
181
|
repo['all'].invoke
|
184
182
|
end
|
185
183
|
|
186
|
-
desc.('sync[{0}]')
|
184
|
+
desc.call('sync[{0}]')
|
187
185
|
task 'sync', [:opts] do |_, args|
|
188
186
|
unless branch || stage == 'init'
|
189
187
|
raise_error('repo not initialized', hint: task_name('repo:init'), kind: LoadError)
|
190
188
|
end
|
191
|
-
parse_opts.(args)
|
189
|
+
parse_opts.call(args)
|
192
190
|
cmd << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}"
|
193
191
|
cmd << '--fail-fast' if failfast
|
194
192
|
puts if newline && stage != 'init'
|
@@ -66,16 +66,17 @@ module Squared
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
attr_reader :sync, :multiple, :parallel
|
69
|
+
attr_reader :exclude, :sync, :multiple, :parallel
|
70
70
|
|
71
71
|
def_delegators :@data, :[], :each, :each_key, :keys, :fetch, :to_a, :to_s, :inspect, :merge!, :key?
|
72
72
|
def_delegators :@workspace, :task_desc, :task_name, :task_namespace, :task_join, :format_desc
|
73
73
|
|
74
|
-
def initialize(workspace)
|
74
|
+
def initialize(workspace, exclude: [])
|
75
75
|
@workspace = workspace
|
76
76
|
@sync = []
|
77
77
|
@multiple = []
|
78
78
|
@parallel = []
|
79
|
+
@exclude = exclude.freeze
|
79
80
|
@session = {
|
80
81
|
group: {},
|
81
82
|
parent: {},
|
@@ -89,7 +90,7 @@ module Squared
|
|
89
90
|
group, parent, id = @session.values
|
90
91
|
ws = proj.workspace
|
91
92
|
@data.each do |key, items|
|
92
|
-
next if (tasks = ws.task_resolve(proj, key)).empty?
|
93
|
+
next if exclude.include?(key) || (tasks = ws.task_resolve(proj, key)).empty?
|
93
94
|
|
94
95
|
if (g = proj.group)
|
95
96
|
id << g
|
@@ -113,13 +114,13 @@ module Squared
|
|
113
114
|
@data.merge!(@session[:parent]) if @session[:id].uniq.size > 1
|
114
115
|
@data.merge!(@session[:group])
|
115
116
|
@data.each do |key, items|
|
116
|
-
next if items.empty? || @workspace.task_exclude?(t = name_get(key))
|
117
|
+
next if items.empty? || exclude.include?(key) || @workspace.task_exclude?(t = name_get(key))
|
117
118
|
|
118
119
|
key = task_name(t)
|
119
120
|
val = format_desc(key, out: true)
|
120
121
|
if items.size > 1
|
121
122
|
@multiple << key
|
122
|
-
if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.(t)
|
123
|
+
if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.call(t)
|
123
124
|
task_desc("#{val} (thread)", name: key)
|
124
125
|
multitask key => items
|
125
126
|
@parallel << key
|
@@ -135,7 +136,7 @@ module Squared
|
|
135
136
|
task_desc(val, name: key)
|
136
137
|
task key => items
|
137
138
|
end
|
138
|
-
@multiple
|
139
|
+
@multiple.concat(sync)
|
139
140
|
end
|
140
141
|
|
141
142
|
def name_get(key)
|
data/lib/squared/workspace.rb
CHANGED
@@ -10,8 +10,7 @@ module Squared
|
|
10
10
|
if id.is_a?(Symbol)
|
11
11
|
project id
|
12
12
|
else
|
13
|
-
|
14
|
-
__get__(:project).find { |_, val| val.path.to_s == id.to_s }
|
13
|
+
__get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id) }
|
15
14
|
end
|
16
15
|
end
|
17
16
|
ret.size == 1 ? ret.first : ret
|
@@ -33,12 +32,6 @@ module Squared
|
|
33
32
|
def project(name)
|
34
33
|
__get__(:project)[name.to_s]
|
35
34
|
end
|
36
|
-
|
37
|
-
def dirpath(val, absolute: true)
|
38
|
-
Pathname.new(val).realdirpath
|
39
|
-
rescue StandardError
|
40
|
-
absolute ? Pathname.pwd.join(val) : Pathname.new(val)
|
41
|
-
end
|
42
35
|
end
|
43
36
|
end
|
44
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- An Pham
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- lib/squared/workspace/project/node.rb
|
98
98
|
- lib/squared/workspace/project/python.rb
|
99
99
|
- lib/squared/workspace/project/ruby.rb
|
100
|
+
- lib/squared/workspace/project/support.rb
|
101
|
+
- lib/squared/workspace/project/support/class.rb
|
100
102
|
- lib/squared/workspace/repo.rb
|
101
103
|
- lib/squared/workspace/series.rb
|
102
104
|
- squared.gemspec
|