Skip to content

Refactor CLI to use Ruby stdlib OptionParser#46

Merged
markets merged 4 commits intomasterfrom
copilot/fix-903c5d72-36dc-4f79-b9f6-51b71edf0e55
Aug 11, 2025
Merged

Refactor CLI to use Ruby stdlib OptionParser#46
markets merged 4 commits intomasterfrom
copilot/fix-903c5d72-36dc-4f79-b9f6-51b71edf0e55

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 11, 2025

Replaces the manual argument parsing in the CLI with Ruby's standard library OptionParser for cleaner, more maintainable code.

Changes

The previous implementation used manual string matching and ARGV manipulation:

if ARGV.include?("--help") || ARGV.include?("-h")
  puts help_message
elsif ARGV.include?("--locale") 
  # Manual index finding and deletion
  index = ARGV.index("--locale")
  locale = ARGV.delete_at(index + 1)
  ARGV.delete_at(index)
  options[:locale] = locale
end

Now uses Ruby's standard OptionParser for declarative option definitions:

parser = OptionParser.new do |opts|
  opts.on("-l", "--locale LOCALE", "Uses the provided locale") do |locale|
    options[:locale] = locale
  end
end

Benefits

  • Cleaner code: Declarative option definitions instead of manual parsing
  • Better error handling: Automatic error messages for invalid options and missing arguments
  • Standard Ruby idioms: Uses stdlib patterns familiar to Ruby developers
  • Easier maintenance: Adding new options requires just one line instead of complex logic
  • Automatic help formatting: OptionParser generates consistent help output

Backward Compatibility

All existing CLI functionality remains identical:

  • All short and long options work exactly the same (-h, --help, -v, --version, etc.)
  • Error handling behavior is preserved
  • All 21 existing tests pass, including 7 CLI-specific tests

This is a pure refactoring with no breaking changes to the public interface.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: markets <576701+markets@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor de CLI to use Ruby stdlib OptionParser Refactor CLI to use Ruby stdlib OptionParser Aug 11, 2025
Copilot AI requested a review from markets August 11, 2025 17:34
@markets markets marked this pull request as ready for review August 11, 2025 18:33
@markets markets merged commit 8300978 into master Aug 11, 2025
12 checks passed
@markets markets deleted the copilot/fix-903c5d72-36dc-4f79-b9f6-51b71edf0e55 branch August 11, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants