workroom 1.0.0 → 1.1.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 +16 -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: ba934ec40dd2fd562407526db171825603588166a1cdcbd757115815f2ef463a
|
|
4
|
+
data.tar.gz: f2b210d1f30f5efa1e8d00c9c0f06dc555439fae28e1decd1e40365fd58b84d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e26cfda013486738f9b16ee329048185be9b4dfc16d391b30ee36427c673b594e21327626c55de188dd619e12eeca11c5087dc2c54a94b592a3db0610acc67fc
|
|
7
|
+
data.tar.gz: '02567952050efaf0862f589097a5808d37c2bb48733cf20c06d57381f92491c7bcc1170b4f36895b461d79849bb4cfcd5cd2f60b2450761c756c3761aad59264'
|
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,7 @@ module Workroom
|
|
|
177
180
|
|
|
178
181
|
return if options[:pretend]
|
|
179
182
|
|
|
180
|
-
result, status = Open3.capture2e(command)
|
|
183
|
+
result, status = Open3.capture2e({ 'WORKROOM_PARENT_DIR' => parent_dir }, command)
|
|
181
184
|
|
|
182
185
|
instance_variable_set :"@#{type}_result", result
|
|
183
186
|
|
|
@@ -294,10 +297,7 @@ module Workroom
|
|
|
294
297
|
end
|
|
295
298
|
|
|
296
299
|
def interactive_delete
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
data = config.read
|
|
300
|
-
_, project = find_project(data)
|
|
300
|
+
_, project = config.find_current_project
|
|
301
301
|
|
|
302
302
|
if !project || !project['workrooms'] || project['workrooms'].empty?
|
|
303
303
|
say 'No workrooms found for this project.'
|
|
@@ -329,10 +329,10 @@ module Workroom
|
|
|
329
329
|
@name = selected_name
|
|
330
330
|
@workroom_path = nil
|
|
331
331
|
|
|
332
|
+
run_teardown_script
|
|
332
333
|
delete_workroom
|
|
333
334
|
cleanup_directory if jj?
|
|
334
335
|
update_config(:remove)
|
|
335
|
-
run_teardown_script
|
|
336
336
|
|
|
337
337
|
say "Workroom '#{name}' deleted successfully.", :green
|
|
338
338
|
|
|
@@ -460,20 +460,6 @@ module Workroom
|
|
|
460
460
|
print_table rows, indent: 2
|
|
461
461
|
end
|
|
462
462
|
|
|
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
463
|
def workroom_warnings(name, info, stored_vcs)
|
|
478
464
|
warnings = []
|
|
479
465
|
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