env_check 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76261979114cfd50eff2593a9d62633313d2f4e2e3c01bb891768f3b7c535cf1
4
- data.tar.gz: 2517760bfbc532e75c0508de1c12cc4a1ed382cfaa27758cfa9f4f0c36dc86e8
3
+ metadata.gz: 6b4d3df17098660e64b172c7b5727fb651146d317a29d73e9650463daa4f86f0
4
+ data.tar.gz: 7a113d7a265ecad73607cb90fd04c436ab90537b593cf00e8ff65142b097946e
5
5
  SHA512:
6
- metadata.gz: 34d26caaacf2100c9389c94a87ebc17b332001fc705f7051adb752b96920178f68c2e873ff401bf50045daf48b9e67df508d0c92a3f4ad7137e976c6a25b83e4
7
- data.tar.gz: 13c03e66845d8afe48d1e62c400b35d89b25a6f01ce2f8b62c701a6359f91c19deceae59ebdef84e07bd8e2efc42204faa87238699e68fdbfbb9a06fd7a1a073
6
+ metadata.gz: ac6b965ae3604b9760a57a007c7b07361ab7f1f55ba272a2d21e2694ff0fea64099f4475ac0995327ac663637bf91a232aa0a5730e231bce979f510cee6aa5d4
7
+ data.tar.gz: 12002c21fceb4f7e7637214a38212b46ddfa64e06765a8b29623bcd5542625a0f542f969e712a22a1a9648476550de36f5b8c2edae72c043e782d142e16fb8b5
data/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ This project adheres to [Semantic Versioning](https://semver.org).
6
6
 
7
7
  ---
8
8
 
9
+ ## [0.1.2] - 2025-07-29
10
+
11
+ ### Fixed
12
+
13
+ - šŸ› **CLI Architecture Redesign** - Completely fixed `bundle exec env_check` compatibility
14
+ - Moved CLI logic from executable to `lib/env_check/cli.rb` as `EnvCheck::CLI` class
15
+ - Simplified executable to just load gem and call CLI class
16
+ - Fixed shebang line and file corruption issues
17
+ - Now works reliably with both `bundle exec` and direct gem installation
18
+
19
+ ---
20
+
21
+ ## [0.1.1] - 2025-07-29
22
+
23
+ ### Fixed
24
+
25
+ - šŸ› **CLI Executable Loading** - Fixed `bundle exec env_check` command not working properly
26
+ - Improved require statement to work in both development and installed gem environments
27
+ - Added fallback loading mechanism for better compatibility
28
+ - Executable now works correctly with bundler in Rails applications
29
+
30
+ ---
31
+
9
32
  ## [0.1.0] - 2025-01-29
10
33
 
11
34
  ### Added
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # šŸ” EnvCheck
2
2
 
3
3
  [![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.0-red.svg)](https://ruby-lang.org)
4
- [![Gem Version](https://badge.fury.io/rb/env_check.svg)](https://badge.fury.io/rb/env_check)
4
+ [![Gem Version](https://img.shields.io/gem/v/env_check.svg?style=flat)](https://rubygems.org/gems/env_check)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
7
  `env_check` is a lightweight Ruby gem to validate and document your environment variables.
data/bin/env_check CHANGED
@@ -3,263 +3,15 @@
3
3
 
4
4
  # bin/env_check - CLI for EnvCheck gem
5
5
 
6
- require "optparse"
7
- require "fileutils"
8
- require_relative "../lib/env_check"
9
-
10
- # Module for CLI output helpers
11
- module CLIHelpers
12
- def success(message)
13
- puts message unless @options[:quiet]
14
- end
15
-
16
- def info(message)
17
- puts message unless @options[:quiet]
18
- end
19
-
20
- def warning(message)
21
- puts "āš ļø #{message}" unless @options[:quiet]
22
- end
23
-
24
- def error(message)
25
- warn message
26
- end
27
-
28
- def error_exit(message, code = 1)
29
- warn "Error: #{message}"
30
- exit code
31
- end
32
-
33
- def default_config_path
34
- Dir.exist?("config") ? "config/env_check.yml" : ".env_check.yml"
35
- end
36
- end
37
-
38
- # CLI class for better organization
39
- class EnvCheckCLI
40
- include CLIHelpers
41
- def initialize(args = ARGV)
42
- @args = args
43
- @options = {
44
- config: nil, # Will be auto-discovered if not specified
45
- quiet: false,
46
- verbose: false
47
- }
48
- @command = nil
49
- end
50
-
51
- def run
52
- parse_arguments
53
- execute_command
54
- rescue StandardError => e
55
- error_exit(e.message.to_s)
56
- end
57
-
58
- private
59
-
60
- def parse_arguments
61
- parser = create_option_parser
62
- parser.parse!(@args)
63
- @command = @args.shift
64
- end
65
-
66
- def create_option_parser
67
- OptionParser.new do |opts|
68
- configure_banner_and_commands(opts)
69
- configure_options(opts)
70
- end
71
- end
72
-
73
- def configure_banner_and_commands(opts)
74
- opts.banner = "Usage: env_check [options] <command>"
75
- opts.separator ""
76
- opts.separator "Commands:"
77
- opts.separator " init Create a new env_check.yml configuration file"
78
- opts.separator " check Validate environment variables against configuration"
79
- opts.separator " version Show version number"
80
- opts.separator ""
81
- opts.separator "Options:"
82
- end
83
-
84
- def configure_options(opts)
85
- opts.on("-c", "--config PATH",
86
- "Configuration file path (auto-discovered: .env_check.yml or config/env_check.yml)") do |path|
87
- @options[:config] = path
88
- end
89
-
90
- opts.on("-q", "--quiet", "Suppress output (only show errors)") do
91
- @options[:quiet] = true
92
- end
93
-
94
- opts.on("-v", "--verbose", "Show detailed output") do
95
- @options[:verbose] = true
96
- end
97
-
98
- opts.on("-h", "--help", "Show this help message") do
99
- puts opts
100
- exit 0
101
- end
102
- end
103
-
104
- def execute_command
105
- case @command
106
- when "init"
107
- init_command
108
- when "check"
109
- check_command
110
- when "version"
111
- version_command
112
- when nil
113
- show_help_and_exit
114
- else
115
- error_exit("Unknown command: #{@command}")
116
- end
117
- end
118
-
119
- def init_command
120
- path = @options[:config] || determine_init_path
121
-
122
- begin
123
- # Create directory if it doesn't exist
124
- dir = File.dirname(path)
125
- FileUtils.mkdir_p(dir) unless dir == "."
126
-
127
- if File.exist?(path)
128
- warning("Configuration file already exists: #{path}")
129
- return
130
- end
131
-
132
- create_config_file(path)
133
- success("Created configuration file: #{path}")
134
-
135
- unless @options[:quiet]
136
- puts "\nNext steps:"
137
- puts "1. Edit #{path} to define your required environment variables"
138
- puts "2. Run 'env_check check' to validate your environment"
139
- end
140
- rescue StandardError => e
141
- error_exit("Failed to create configuration file: #{e.message}")
142
- end
143
- end
144
-
145
- def check_command
146
- path = @options[:config] || EnvCheck::Config.discover_config_path
147
- validate_config_exists(path)
148
-
149
- info("Checking environment variables using: #{path}") if @options[:verbose]
150
-
151
- result = perform_validation(path)
152
- handle_validation_result(result)
153
- end
154
-
155
- def validate_config_exists(path)
156
- return if File.exist?(path)
157
-
158
- error_exit("Configuration file not found: #{path}. Run 'env_check init' first.")
159
- end
160
-
161
- def perform_validation(path)
162
- EnvCheck.verify(path)
163
- rescue EnvCheck::Error => e
164
- error_exit("Validation failed: #{e.message}")
165
- rescue StandardError => e
166
- error_exit("Unexpected error: #{e.message}")
167
- end
168
-
169
- def handle_validation_result(result)
170
- if result.success?
171
- handle_success_result(result)
172
- else
173
- handle_failure_result(result)
174
- end
175
- end
176
-
177
- def handle_success_result(result)
178
- success("āœ… All environment variables are valid!")
179
-
180
- if @options[:verbose] && !result.valid_vars.empty?
181
- puts "\nValid variables:"
182
- result.valid_vars.each { |var| puts " āœ… #{var}" }
183
- end
184
-
185
- display_warnings(result.warnings) unless result.warnings.empty?
186
- end
187
-
188
- def handle_failure_result(result)
189
- error("āŒ Environment validation failed!")
190
-
191
- display_errors(result.errors) unless result.errors.empty?
192
- display_warnings(result.warnings) unless result.warnings.empty?
193
-
194
- exit 1
195
- end
196
-
197
- def display_errors(errors)
198
- puts "\nErrors:"
199
- errors.each { |error| puts " āŒ #{error}" }
200
- end
201
-
202
- def display_warnings(warnings)
203
- puts "\nWarnings:"
204
- warnings.each { |warning| puts " āš ļø #{warning}" }
205
- end
206
-
207
- def version_command
208
- puts EnvCheck::VERSION
209
- end
210
-
211
- def create_config_file(path)
212
- File.write(path, config_template)
213
- end
214
-
215
- def config_template
216
- <<~YAML
217
- # EnvCheck Configuration
218
- # Configure required and optional environment variables for your application
219
-
220
- # Required environment variables (must be present and non-empty)
221
- required:
222
- - DATABASE_URL
223
- - SECRET_KEY_BASE
224
-
225
- # Optional environment variables with type validation
226
- optional:
227
- DEBUG: boolean # true, false, 1, 0, yes, no, on, off (case-insensitive)
228
- PORT: port # valid port number (1-65535)
229
- API_URL: url # must start with http:// or https://
230
- ADMIN_EMAIL: email # valid email format
231
- LOG_LEVEL: string # any string value
232
- RATE_LIMIT: float # floating point number
233
- CONFIG_PATH: path # file or directory path
234
- SETTINGS: json # valid JSON string
235
- #{" "}
236
- # You can also configure per-environment settings:
237
- # development:
238
- # required:
239
- # - DATABASE_URL
240
- # optional:
241
- # DEBUG: boolean
242
- ##{" "}
243
- # production:
244
- # required:
245
- # - DATABASE_URL
246
- # - SECRET_KEY_BASE
247
- # - RAILS_MASTER_KEY
248
- # optional:
249
- # REDIS_URL: url
250
- YAML
251
- end
252
-
253
- def show_help_and_exit
254
- puts create_option_parser.help
255
- exit 1
256
- end
257
-
258
- # Determine the best path for init command
259
- def determine_init_path
260
- default_config_path
261
- end
6
+ # Ensure we can load the gem whether it's installed or in development
7
+ begin
8
+ require "env_check"
9
+ rescue LoadError
10
+ # If we can't load the gem, try to add lib to load path (for development)
11
+ lib_path = File.expand_path("../lib", __dir__)
12
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
13
+ require "env_check"
262
14
  end
263
15
 
264
16
  # Run the CLI
265
- EnvCheckCLI.new.run if __FILE__ == $PROGRAM_NAME
17
+ EnvCheck::CLI.new(ARGV).run
@@ -0,0 +1,239 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "fileutils"
5
+
6
+ module EnvCheck
7
+ # Module for CLI output helpers
8
+ module CLIHelpers
9
+ def success(message)
10
+ puts message unless @options[:quiet]
11
+ end
12
+
13
+ def info(message)
14
+ puts message unless @options[:quiet]
15
+ end
16
+
17
+ def warning(message)
18
+ puts "āš ļø #{message}" unless @options[:quiet]
19
+ end
20
+
21
+ def error(message)
22
+ warn message
23
+ end
24
+
25
+ def error_exit(message, code = 1)
26
+ warn "Error: #{message}"
27
+ exit code
28
+ end
29
+
30
+ def default_config_path
31
+ Dir.exist?("config") ? "config/env_check.yml" : ".env_check.yml"
32
+ end
33
+ end
34
+
35
+ # CLI class for better organization
36
+ class CLI
37
+ include CLIHelpers
38
+
39
+ def initialize(args = ARGV)
40
+ @args = args
41
+ @options = {
42
+ config: nil, # Will be auto-discovered if not specified
43
+ quiet: false,
44
+ verbose: false
45
+ }
46
+ @command = nil
47
+ end
48
+
49
+ def run
50
+ parse_arguments
51
+ execute_command
52
+ rescue StandardError => e
53
+ error_exit(e.message.to_s)
54
+ end
55
+
56
+ private
57
+
58
+ def parse_arguments
59
+ parser = create_option_parser
60
+ parser.parse!(@args)
61
+ @command = @args.shift
62
+ end
63
+
64
+ def create_option_parser
65
+ OptionParser.new do |opts|
66
+ configure_banner_and_commands(opts)
67
+ configure_options(opts)
68
+ end
69
+ end
70
+
71
+ def configure_banner_and_commands(opts)
72
+ opts.banner = "Usage: env_check [options] <command>"
73
+ opts.separator ""
74
+ opts.separator "Commands:"
75
+ opts.separator " init Create a new env_check.yml configuration file"
76
+ opts.separator " check Validate environment variables against configuration"
77
+ opts.separator " version Show version number"
78
+ opts.separator ""
79
+ opts.separator "Options:"
80
+ end
81
+
82
+ def configure_options(opts)
83
+ opts.on("-c", "--config PATH",
84
+ "Configuration file path (auto-discovered: .env_check.yml or config/env_check.yml)") do |path|
85
+ @options[:config] = path
86
+ end
87
+
88
+ opts.on("-q", "--quiet", "Suppress output (only show errors)") do
89
+ @options[:quiet] = true
90
+ end
91
+
92
+ opts.on("-v", "--verbose", "Show detailed output") do
93
+ @options[:verbose] = true
94
+ end
95
+
96
+ opts.on("-h", "--help", "Show this help message") do
97
+ puts opts
98
+ exit 0
99
+ end
100
+ end
101
+
102
+ def execute_command
103
+ case @command
104
+ when "init"
105
+ init_command
106
+ when "check"
107
+ check_command
108
+ when "version"
109
+ version_command
110
+ when nil
111
+ show_help_and_exit
112
+ else
113
+ error_exit("Unknown command: #{@command}")
114
+ end
115
+ end
116
+
117
+ def init_command
118
+ path = @options[:config] || determine_init_path
119
+
120
+ begin
121
+ # Create directory if it doesn't exist
122
+ dir = File.dirname(path)
123
+ FileUtils.mkdir_p(dir) unless dir == "."
124
+
125
+ if File.exist?(path)
126
+ warning("Configuration file already exists: #{path}")
127
+ return
128
+ end
129
+
130
+ create_config_file(path)
131
+ success("Created configuration file: #{path}")
132
+
133
+ unless @options[:quiet]
134
+ puts "\nNext steps:"
135
+ puts "1. Edit #{path} to define your required environment variables"
136
+ puts "2. Run 'env_check check' to validate your environment"
137
+ end
138
+ rescue StandardError => e
139
+ error_exit("Failed to create configuration file: #{e.message}")
140
+ end
141
+ end
142
+
143
+ def check_command
144
+ config_path = find_config_file
145
+
146
+ error_exit("No configuration file found. Run 'env_check init' to create one.") if config_path.nil?
147
+
148
+ begin
149
+ result = EnvCheck.verify(config_path)
150
+ display_results(result)
151
+ exit 1 unless result.success?
152
+ rescue StandardError => e
153
+ error_exit("Validation failed: #{e.message}")
154
+ end
155
+ end
156
+
157
+ def version_command
158
+ puts EnvCheck::VERSION
159
+ end
160
+
161
+ def create_config_file(path)
162
+ File.write(path, config_template)
163
+ end
164
+
165
+ def config_template
166
+ <<~YAML
167
+ # EnvCheck Configuration#{Dir.exist?("config") ? " (Rails)" : " (Root Level)"}
168
+ # Configure required and optional environment variables for your application
169
+
170
+ # Required environment variables (must be present and non-empty)
171
+ required:
172
+ - DATABASE_URL
173
+ - SECRET_KEY_BASE
174
+
175
+ # Optional environment variables with type validation
176
+ optional:
177
+ DEBUG: boolean # true, false, 1, 0, yes, no (case-insensitive)
178
+ PORT: integer # numeric values only
179
+ API_URL: url # must start with http:// or https://
180
+ ADMIN_EMAIL: email # valid email format
181
+ LOG_LEVEL: string # any string value
182
+ YAML
183
+ end
184
+
185
+ def find_config_file
186
+ return @options[:config] if @options[:config]
187
+
188
+ # Check ENV variable first
189
+ return ENV["ENV_CHECK_CONFIG"] if ENV["ENV_CHECK_CONFIG"]
190
+
191
+ # Smart discovery
192
+ candidates = [".env_check.yml", "config/env_check.yml"]
193
+ candidates.find { |path| File.exist?(path) }
194
+ end
195
+
196
+ def display_results(result)
197
+ # Show valid variables
198
+ result.valid_vars.each do |var|
199
+ success("āœ… #{var} is set")
200
+ end
201
+
202
+ # Show warnings for optional variables
203
+ result.warnings.each do |warning|
204
+ warning(warning)
205
+ end
206
+
207
+ # Show errors for required variables
208
+ result.errors.each do |error|
209
+ error("āŒ #{error}")
210
+ end
211
+
212
+ # Summary
213
+ if result.success?
214
+ success("\nāœ… Environment validation passed!")
215
+ info("Valid variables: #{result.valid_vars.count}")
216
+ info("Warnings: #{result.warnings.count}") if result.warnings.any?
217
+ else
218
+ error("\nāŒ Environment validation failed!")
219
+ error("\nErrors:")
220
+ result.errors.each { |err| error(" āŒ #{err}") }
221
+
222
+ if result.warnings.any?
223
+ info("\nWarnings:")
224
+ result.warnings.each { |warn| info(" āš ļø #{warn}") }
225
+ end
226
+ end
227
+ end
228
+
229
+ def show_help_and_exit
230
+ puts create_option_parser.help
231
+ exit 1
232
+ end
233
+
234
+ # Determine the best path for init command
235
+ def determine_init_path
236
+ default_config_path
237
+ end
238
+ end
239
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EnvCheck
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/env_check.rb CHANGED
@@ -15,6 +15,7 @@ require "yaml"
15
15
  require_relative "env_check/version"
16
16
  require_relative "env_check/config"
17
17
  require_relative "env_check/validators"
18
+ require_relative "env_check/cli"
18
19
  require_relative "env_check/rake_task" if defined?(Rake)
19
20
 
20
21
  # Load .env automatically (if present)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammad Nadeem
@@ -174,6 +174,7 @@ files:
174
174
  - bin/env_check
175
175
  - bin/setup
176
176
  - lib/env_check.rb
177
+ - lib/env_check/cli.rb
177
178
  - lib/env_check/config.rb
178
179
  - lib/env_check/rake_task.rb
179
180
  - lib/env_check/validators.rb