workroom 1.0.0 → 1.2.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 +4 -4
- data/README.md +7 -1
- data/lib/workroom/commands.rb +19 -30
- data/lib/workroom/config.rb +19 -0
- data/lib/workroom/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cbab7dff475bb494c5bc1d94872f6a64278078a56c89b5db0cf1a39dfda25d59
|
|
4
|
+
data.tar.gz: 1d6f8ca33e27a3d85844b193630971f8358444cbbffcc47015e3c18a03d7a3b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45e1ab6a3b868f79514a8418cb721182d7b28f5e5a920a77761ff86cbd6329513e737776b8c6f08d05b868b37c6f15ce951e50ff81c39f100863ec4a3d8e4903
|
|
7
|
+
data.tar.gz: cc00a9e83bc839c9e6183cd445306c297133af448bfcc2e9510cd51655e09e1b987df13ef0723ec09aa66bc9b198fb9ed6587eee32c3f098dc07040225d24472
|
data/README.md
CHANGED
|
@@ -85,7 +85,13 @@ Place an executable script at `scripts/workroom_setup` in your project. It will
|
|
|
85
85
|
|
|
86
86
|
### Teardown script
|
|
87
87
|
|
|
88
|
-
Place an executable script at `scripts/workroom_teardown` in your project. It will run
|
|
88
|
+
Place an executable script at `scripts/workroom_teardown` in your project. It will run inside the workroom directory before it is deleted.
|
|
89
|
+
|
|
90
|
+
### Environment variables
|
|
91
|
+
|
|
92
|
+
The following environment variables are available to setup and teardown scripts:
|
|
93
|
+
|
|
94
|
+
- `WORKROOM_PARENT_DIR` - The absolute path to the parent project directory. Since scripts run inside the workroom directory, this lets you reference files in the original project root.
|
|
89
95
|
|
|
90
96
|
## Rails integration
|
|
91
97
|
|
data/lib/workroom/commands.rb
CHANGED
|
@@ -64,8 +64,7 @@ module Workroom
|
|
|
64
64
|
|
|
65
65
|
desc 'list|l|ls', 'List all workrooms for the current project'
|
|
66
66
|
def list
|
|
67
|
-
|
|
68
|
-
project_path, project = find_project(data)
|
|
67
|
+
project_path, project = config.find_current_project
|
|
69
68
|
|
|
70
69
|
# Inside a workroom
|
|
71
70
|
if project && Pathname.pwd.to_s != project_path
|
|
@@ -87,13 +86,12 @@ module Workroom
|
|
|
87
86
|
end
|
|
88
87
|
|
|
89
88
|
# Neither — list all workrooms grouped by parent
|
|
90
|
-
|
|
91
|
-
if projects_with_workrooms.empty?
|
|
89
|
+
if config.projects_with_workrooms.empty?
|
|
92
90
|
say 'No workrooms found.'
|
|
93
91
|
return
|
|
94
92
|
end
|
|
95
93
|
|
|
96
|
-
projects_with_workrooms.each do |path, proj|
|
|
94
|
+
config.projects_with_workrooms.each do |path, proj|
|
|
97
95
|
say "#{display_path(path)}:"
|
|
98
96
|
inside path do
|
|
99
97
|
list_workrooms(proj['workrooms'], proj['vcs'])
|
|
@@ -106,13 +104,14 @@ module Workroom
|
|
|
106
104
|
method_option :confirm, type: :string,
|
|
107
105
|
desc: 'Skip confirmation if value matches the workroom name'
|
|
108
106
|
def delete(name = nil)
|
|
107
|
+
check_not_in_workroom!
|
|
108
|
+
|
|
109
109
|
if !name
|
|
110
110
|
interactive_delete
|
|
111
111
|
return
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
@name = name
|
|
115
|
-
check_not_in_workroom!
|
|
116
115
|
validate_name!
|
|
117
116
|
|
|
118
117
|
if !options[:pretend]
|
|
@@ -141,13 +140,14 @@ module Workroom
|
|
|
141
140
|
def run_setup_script
|
|
142
141
|
return if !setup_script.exist?
|
|
143
142
|
|
|
143
|
+
parent_dir = Pathname.pwd.to_s
|
|
144
144
|
inside workroom_path do
|
|
145
|
-
run_user_script :setup, setup_script_to_run.to_s
|
|
145
|
+
run_user_script :setup, setup_script_to_run.to_s, parent_dir
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
def setup_script
|
|
150
|
-
@setup_script ||=
|
|
150
|
+
@setup_script ||= Pathname.pwd.join('scripts', 'workroom_setup')
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
def setup_script_to_run
|
|
@@ -157,7 +157,10 @@ module Workroom
|
|
|
157
157
|
def run_teardown_script
|
|
158
158
|
return if !teardown_script.exist?
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
parent_dir = Pathname.pwd.to_s
|
|
161
|
+
inside workroom_path do
|
|
162
|
+
run_user_script :teardown, teardown_script_to_run.to_s, parent_dir
|
|
163
|
+
end
|
|
161
164
|
end
|
|
162
165
|
|
|
163
166
|
def teardown_script
|
|
@@ -168,7 +171,7 @@ module Workroom
|
|
|
168
171
|
teardown_script
|
|
169
172
|
end
|
|
170
173
|
|
|
171
|
-
def run_user_script(type, command)
|
|
174
|
+
def run_user_script(type, command, parent_dir)
|
|
172
175
|
return if behavior != :invoke
|
|
173
176
|
|
|
174
177
|
destination = relative_to_original_destination_root(destination_root, false)
|
|
@@ -177,7 +180,10 @@ module Workroom
|
|
|
177
180
|
|
|
178
181
|
return if options[:pretend]
|
|
179
182
|
|
|
180
|
-
result, status = Open3.capture2e(
|
|
183
|
+
result, status = Open3.capture2e({
|
|
184
|
+
'WORKROOM_NAME' => name,
|
|
185
|
+
'WORKROOM_PARENT_DIR' => parent_dir
|
|
186
|
+
}, command)
|
|
181
187
|
|
|
182
188
|
instance_variable_set :"@#{type}_result", result
|
|
183
189
|
|
|
@@ -294,10 +300,7 @@ module Workroom
|
|
|
294
300
|
end
|
|
295
301
|
|
|
296
302
|
def interactive_delete
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
data = config.read
|
|
300
|
-
_, project = find_project(data)
|
|
303
|
+
_, project = config.find_current_project
|
|
301
304
|
|
|
302
305
|
if !project || !project['workrooms'] || project['workrooms'].empty?
|
|
303
306
|
say 'No workrooms found for this project.'
|
|
@@ -329,10 +332,10 @@ module Workroom
|
|
|
329
332
|
@name = selected_name
|
|
330
333
|
@workroom_path = nil
|
|
331
334
|
|
|
335
|
+
run_teardown_script
|
|
332
336
|
delete_workroom
|
|
333
337
|
cleanup_directory if jj?
|
|
334
338
|
update_config(:remove)
|
|
335
|
-
run_teardown_script
|
|
336
339
|
|
|
337
340
|
say "Workroom '#{name}' deleted successfully.", :green
|
|
338
341
|
|
|
@@ -460,20 +463,6 @@ module Workroom
|
|
|
460
463
|
print_table rows, indent: 2
|
|
461
464
|
end
|
|
462
465
|
|
|
463
|
-
# Find the project for the current directory. If pwd is a project in the config, return it
|
|
464
|
-
# directly. Otherwise, check if pwd is a workroom path under any project.
|
|
465
|
-
def find_project(data)
|
|
466
|
-
pwd = Pathname.pwd.to_s
|
|
467
|
-
return [pwd, data[pwd]] if data.key?(pwd)
|
|
468
|
-
|
|
469
|
-
data.each do |project_path, project|
|
|
470
|
-
workrooms = project['workrooms'] || {}
|
|
471
|
-
return [project_path, project] if workrooms.any? { |_, info| info['path'] == pwd }
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
[pwd, nil]
|
|
475
|
-
end
|
|
476
|
-
|
|
477
466
|
def workroom_warnings(name, info, stored_vcs)
|
|
478
467
|
warnings = []
|
|
479
468
|
warnings << 'directory not found' if !Dir.exist?(info['path'])
|
data/lib/workroom/config.rb
CHANGED
|
@@ -40,6 +40,25 @@ module Workroom
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# Find the project for the current directory. If pwd is a project in the config, return it
|
|
44
|
+
# directly. Otherwise, check if pwd is a workroom path under any project.
|
|
45
|
+
def find_current_project
|
|
46
|
+
data = read
|
|
47
|
+
pwd = Pathname.pwd.to_s
|
|
48
|
+
return [pwd, data[pwd]] if data.key?(pwd)
|
|
49
|
+
|
|
50
|
+
data.each do |project_path, project|
|
|
51
|
+
workrooms = project['workrooms'] || {}
|
|
52
|
+
return [project_path, project] if workrooms.any? { |_, info| info['path'] == pwd }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
[pwd, nil]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def projects_with_workrooms
|
|
59
|
+
@projects_with_workrooms ||= read.select { |_, p| p['workrooms']&.any? }
|
|
60
|
+
end
|
|
61
|
+
|
|
43
62
|
def workrooms_dir
|
|
44
63
|
Pathname.new(File.expand_path(read['workrooms_dir'] || DEFAULT_WORKROOMS_DIR))
|
|
45
64
|
end
|
data/lib/workroom/version.rb
CHANGED