-
Notifications
You must be signed in to change notification settings - Fork 5
/
gather.rb
executable file
·186 lines (151 loc) · 4.98 KB
/
gather.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env ruby
require 'optparse'
require 'open3'
# Default output method and content
output_method = 'stdout'
output_content = ""
# Detect the operating system
os_type = RbConfig::CONFIG['host_os']
# Determine the clipboard command based on the OS
clipboard_command = case os_type
when /darwin/
'pbcopy'
when /linux/
'xclip -selection clipboard'
else
puts "Unsupported OS type: #{os_type}"
exit 1
end
# Check if required commands are available
def check_dependency(command, install_instructions)
unless system("command -v #{command} > /dev/null")
puts "#{command} is not installed. Please install it using:"
puts install_instructions
exit 1
end
end
# Check for necessary dependencies
check_dependency('tree', "sudo apt install tree") if os_type =~ /linux/
check_dependency('xclip', "sudo apt install xclip") if os_type =~ /linux/ && clipboard_command == 'xclip -selection clipboard'
# Usage message
def usage
puts "Usage: #{$0} [-o output_method] [-f output_file]"
puts " -o, --output Output method: stdout, clipboard, or file (default: stdout)"
puts " -f, --file Output file path (required if output method is file)"
exit 1
end
# Parse command-line arguments
options = {}
OptionParser.new do |opts|
opts.on('-o', '--output OUTPUT', 'Output method') { |o| options[:output] = o }
opts.on('-f', '--file FILE', 'Output file path') { |f| options[:file] = f }
opts.on('-h', '--help', 'Show help') { usage }
end.parse!
output_method = options[:output] if options[:output]
output_file = options[:file]
# Function to output content based on selected output method
def output(content)
$output_content ||= ""
$output_content += "#{content}\n"
end
# Function to finalize output
def finalize_output(output_method, output_file, clipboard_command)
case output_method
when 'stdout'
puts $output_content
when 'clipboard'
IO.popen(clipboard_command, 'w') { |clipboard| clipboard.write($output_content) }
when 'file'
File.write(output_file, $output_content)
else
puts 'Invalid output method'
exit 1
end
end
# Check if file output is specified but no file is given
if output_method == 'file' && output_file.nil?
puts 'Error: Output file must be specified when using file output method.'
usage
end
# Start the script output
output "=== Directory Structure and File Contents ===\n"
# Functions for tasks
def show_tree(dir)
if system('command -v tree > /dev/null')
output "Tree for #{dir}:\n"
output `tree #{dir}`
else
# Fallback: List directories recursively if 'tree' is not available
output "Directory listing for #{dir} (fallback):\n"
output Dir.glob("#{dir}/**/*").map { |f| File.directory?(f) ? "#{f}/" : f }.join("\n")
end
end
def show_file_content(file)
output "Contents of #{file}:\n"
output File.read(file)
end
# Main tasks
show_tree 'app'
show_tree 'db'
output "=== Contents of Ruby Files in db/ ===\n"
Dir.glob('db/*.rb').each do |file|
output "File: #{file}\n"
output File.read(file)
end
show_tree 'config'
output "=== Config Files ===\n"
show_file_content 'config/database.yml'
output "=== Contents of Ruby Files in config/environments/ ===\n"
Dir.glob('config/environments/*.rb').each do |file|
output "File: #{file}\n"
output File.read(file)
end
show_file_content 'config/routes.rb'
show_file_content 'config/tailwind.config.js'
show_tree 'terraform'
output "=== Terraform Files ===\n"
Dir.glob('terraform/**/*.tf').each do |file|
output "Processing file: #{file}\n"
output File.read(file)
end
output "=== App Directory Files (Ruby and HTML ERB) ===\n"
Dir.glob('app/**/*.{rb,html.erb}').each do |file|
output "Processing file: #{file}\n"
output File.read(file)
end
output "=== GitHub Workflow Files ===\n"
Dir.glob('.github/workflows/*.yml').each do |file|
output "File: #{file}\n"
output File.read(file)
end
show_tree 'bin'
output "=== Spec Directory Files (Ruby) ===\n"
Dir.glob('spec/**/*.rb').each do |file|
output "File: #{file}\n"
output File.read(file)
end
output "=== Public Directory (One Level Deep) ===\n"
output `tree -L 1 public` if system('command -v tree > /dev/null')
output "=== Rake Files in lib/tasks/ ===\n"
Dir.glob('lib/tasks/*.rake').each do |file|
output "File: #{file}\n"
output File.read(file)
end
output "=== Other Configurations and Files ===\n"
['Procfile.dev', 'Gemfile', 'docker-compose.prod.yml', 'Dockerfile', '.ruby-version', 'package.json'].each do |file|
show_file_content file
end
output "=== Vite Configuration Files ===\n"
Dir.glob('vite.config.*').each do |file|
output "File: #{file}\n"
output File.read(file)
end
['.gitignore', '.dockerignore'].each do |file|
show_file_content file
end
output "=== Generated env.example from .env ===\n"
output `sed 's/=.*/=/' .env`
# End of script
output "=== End of Output ===\n"
# Finalize output
finalize_output(output_method, output_file, clipboard_command)