diff --git a/exe/ruby_ast_gen b/exe/ruby_ast_gen index 3d6b36b..5be3907 100755 --- a/exe/ruby_ast_gen +++ b/exe/ruby_ast_gen @@ -11,6 +11,7 @@ options = { input: nil, output: '.ast', exclude: '^(tests?|vendor|spec)', + debug: false } # Parse ARGV manually @@ -26,6 +27,9 @@ while i < ARGV.size when '-e', '--exclude' i += 1 options[:exclude] = ARGV[i] + when '-d', '--debug' + i += 1 + options[:debug] = true when '--version' puts RubyAstGen::VERSION exit @@ -35,6 +39,7 @@ Usage: -i, --input The input file or directory (required) -o, --output The output directory (default: '.ast') -e, --exclude The exclusion regex (default: '^(tests?|vendor|spec)') + -d, --debug Enable debug logging --version Print the version --help Print usage HELP diff --git a/lib/ruby_ast_gen.rb b/lib/ruby_ast_gen.rb index 116f762..fc93585 100644 --- a/lib/ruby_ast_gen.rb +++ b/lib/ruby_ast_gen.rb @@ -10,6 +10,10 @@ module RubyAstGen module Logger + def self.debug(message) + puts "[DEBUG] #{message}" + end + def self.info(message) puts "[INFO] #{message}" end @@ -25,10 +29,18 @@ def self.error(message) # Main method to parse the input and generate the AST output def self.parse(opts) + if opts[:debug] + RubyAstGen::Logger::debug "CLI Arguments received: #{opts}" + end + input_path = opts[:input] output_dir = opts[:output] exclude_regex = Regexp.new(opts[:exclude]) + if opts[:debug] + RubyAstGen::Logger::debug "Exclude Regex Received: #{exclude_regex}" + end + FileUtils.mkdir_p(output_dir) if File.file?(input_path)