used_env 0.0.3 → 0.0.15
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/bin/used_env +27 -0
- data/lib/env_list.rb +28 -0
- data/lib/used_env.rb +49 -9
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 425e84628abce9fa6d4c48125f5c94a22201a4669973566d1421a07470385f79
|
|
4
|
+
data.tar.gz: dfba9fda36cd3cae9589427a0eaedb58a2835ee015b7034d71abd235e35507d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20e6f141cb60b5e2910299e795ebee27718593496407263a5a9a9c5d6c43901f7655ad4d2faeb3fbc77e893202806feadad8ce1b49206ff60d1890eb62907038
|
|
7
|
+
data.tar.gz: 06fef92b837557ec34836021c98c9f0183ce5b5a7142a78e71418b81322c71f2cce85d68174e9f8912e1617b8dc819baf01953d7efbe2cae8ec7f408356960f9
|
data/bin/used_env
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Load the current working directory
|
|
2
|
+
root_path = Dir.pwd
|
|
3
|
+
|
|
4
|
+
# Require the UsedEnv class and Rails environment if applicable
|
|
5
|
+
require "used_env"
|
|
6
|
+
require_relative "#{root_path}/config/environment"
|
|
7
|
+
|
|
8
|
+
# Display usage instructions if no arguments are provided
|
|
9
|
+
if ARGV.empty?
|
|
10
|
+
puts UsedEnv.find_env_variables
|
|
11
|
+
exit
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Handle command-line arguments
|
|
15
|
+
case ARGV.first
|
|
16
|
+
when "--valid"
|
|
17
|
+
# puts "Set ENV Variables:"
|
|
18
|
+
UsedEnv.display_envs("valid")
|
|
19
|
+
when "--invalid"
|
|
20
|
+
# puts "Unset ENV Variables:"
|
|
21
|
+
UsedEnv.display_envs("invalid")
|
|
22
|
+
else
|
|
23
|
+
puts "Invalid option! Use one of the following:"
|
|
24
|
+
puts " --valid : Display environment variables that are set"
|
|
25
|
+
puts " --invalid : Display environment variables that are unset"
|
|
26
|
+
exit
|
|
27
|
+
end
|
data/lib/env_list.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Env_list
|
|
2
|
+
def self.load_env
|
|
3
|
+
keys=[]
|
|
4
|
+
File.foreach(".env") do |line|
|
|
5
|
+
next if line.strip.empty? || line.start_with?('#')
|
|
6
|
+
|
|
7
|
+
key,value=line.strip.split("=",2)
|
|
8
|
+
ENV[key]=value if key && value
|
|
9
|
+
|
|
10
|
+
keys.push(key)
|
|
11
|
+
end
|
|
12
|
+
# display key value pair
|
|
13
|
+
# keys.each do |k|
|
|
14
|
+
# # puts "#{k}"
|
|
15
|
+
# # +ENV[k]
|
|
16
|
+
# end
|
|
17
|
+
return keys
|
|
18
|
+
# puts "zebra"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
# Env_list.load_env('.env')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Env_list.load_env
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
data/lib/used_env.rb
CHANGED
|
@@ -1,24 +1,64 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
1
3
|
class UsedEnv
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
Reset= "\e[0m"
|
|
5
|
+
Green= "\e[32m"
|
|
6
|
+
Red= "\e[31m"
|
|
7
|
+
Yellow= "\e[33m"
|
|
8
|
+
|
|
9
|
+
def self.find_files
|
|
10
|
+
Dir["./**/*.{rb,html,erb,yml}"]
|
|
4
11
|
end
|
|
5
12
|
|
|
6
13
|
def self.find_env_variables
|
|
7
|
-
file_names = find_ruby_files
|
|
8
14
|
env_vars = []
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
|
|
16
|
+
find_files.each do |file|
|
|
17
|
+
File.foreach(file).with_index do |line, line_num|
|
|
11
18
|
next if line.strip.empty? || line.strip.start_with?('#')
|
|
12
19
|
|
|
13
|
-
# matches =line.scan(/ENV\["(.*?)"\]|ENV\['(.*?)'\]|ENV\.fetch\(["'](.*?)["']\)/)
|
|
14
20
|
matches = line.scan(/ENV\[["'](.*?)["']\]|ENV\.fetch\(["'](.*?)["']\)/)
|
|
15
|
-
|
|
16
21
|
matches.flatten.compact.each do |env_var|
|
|
17
|
-
env_vars << {
|
|
22
|
+
env_vars << { name: env_var, file: file, line: line_num + 1 }
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
25
|
end
|
|
21
|
-
|
|
26
|
+
|
|
27
|
+
env_vars.uniq
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.categorize_env_variables
|
|
31
|
+
categorized = { set: [], unset: [] }
|
|
32
|
+
|
|
33
|
+
find_env_variables.each do |env|
|
|
34
|
+
# if ENV[env[:name]]
|
|
35
|
+
value = ENV[env[:name]]
|
|
36
|
+
if value.nil? || value.empty?
|
|
37
|
+
categorized[:unset] << env
|
|
38
|
+
else
|
|
39
|
+
categorized[:set] << env
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
categorized
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.display_envs(check)
|
|
47
|
+
categorized = categorize_env_variables
|
|
48
|
+
case check
|
|
49
|
+
when 'valid'
|
|
50
|
+
puts "Set ENV Variables:"
|
|
51
|
+
categorized[:set].each { |env| puts "#{Green}#{env[:name]} -#{Yellow} #{env[:file]}:#{env[:line]} #{Reset} " }
|
|
52
|
+
when 'invalid'
|
|
53
|
+
puts "Unset ENV Variables:"
|
|
54
|
+
categorized[:unset].each { |env| puts "#{Red}#{env[:name]} -#{Yellow} #{env[:file]}:#{env[:line]} #{Reset}" }
|
|
55
|
+
else
|
|
56
|
+
puts "Invalid option! Use 'valid' or 'invalid'."
|
|
57
|
+
end
|
|
22
58
|
end
|
|
23
59
|
end
|
|
60
|
+
# UsedEnv.display_envs("valid")
|
|
61
|
+
# UsedEnv.display_envs("invalid")
|
|
62
|
+
|
|
63
|
+
# puts UsedEnv.find_env_variables
|
|
24
64
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: used_env
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Habi Pyatha
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-12-
|
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
A gem to list all the environment variables used in a Ruby project.
|
|
@@ -19,11 +19,15 @@ description: |
|
|
|
19
19
|
results.each do |entry|
|
|
20
20
|
puts "ENV_Variable: #{entry[:variable]} | File_path: #{entry[:file]} | Line: #{entry[:line]}"
|
|
21
21
|
end
|
|
22
|
+
..........used_env..........used_env --valid............used_env --invalid.............
|
|
22
23
|
email:
|
|
23
|
-
executables:
|
|
24
|
+
executables:
|
|
25
|
+
- used_env
|
|
24
26
|
extensions: []
|
|
25
27
|
extra_rdoc_files: []
|
|
26
28
|
files:
|
|
29
|
+
- bin/used_env
|
|
30
|
+
- lib/env_list.rb
|
|
27
31
|
- lib/used_env.rb
|
|
28
32
|
homepage:
|
|
29
33
|
licenses: []
|