Class: Rfmt::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rfmt/cli.rb

Overview

Command Line Interface for rfmt

Constant Summary collapse

PROGRESS_THRESHOLD =

Constants

20
PROGRESS_INTERVAL =

Show progress for file counts >= this

10

Instance Method Summary collapse

Instance Method Details

#check(*files) ⇒ Object



113
114
115
# File 'lib/rfmt/cli.rb', line 113

def check(*files)
  invoke :format, files, check: true, write: false
end

#config_cmdObject



124
125
126
127
128
# File 'lib/rfmt/cli.rb', line 124

def config_cmd
  config = load_config
  require 'json'
  say JSON.pretty_generate(config.config)
end

#format(*files) ⇒ Object



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
# File 'lib/rfmt/cli.rb', line 70

def format(*files)
  config = load_config
  files = files.empty? ? config.files_to_format : files.flatten

  if files.empty?
    say 'No files to format', :yellow
    return
  end

  # Initialize and use cache if enabled
  cache = initialize_cache_if_enabled
  files = filter_files_with_cache(files, cache)

  if files.empty?
    say '✓ All files are already formatted (cached)', :cyan
    return
  end

  # Show progress message (unless in quiet mode)
  unless options[:quiet]
    if files.size == 1
      say "Processing #{files.first}...", :blue
    else
      say "Processing #{files.size} file(s)...", :blue
    end
  end

  use_parallel = should_use_parallel?(files)

  if options[:verbose] && files.size > 1
    mode = use_parallel ? "parallel (#{options[:jobs] || 'auto'} jobs)" : 'sequential'
    say "Using #{mode} processing for #{files.size} files", :blue
  end

  results = if use_parallel
              format_files_parallel(files)
            else
              format_files_sequential(files)
            end
  handle_results(results, cache)
end

#initObject



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/rfmt/cli.rb', line 136

def init
  config_file = options[:path] || '.rfmt.yml'

  # Use Rfmt::Config module for consistent behavior
  result = Rfmt::Config.init(config_file, force: options[:force] || false)

  if result
    say "Created #{config_file}", :green
  else
    say "Configuration file already exists at #{config_file}. Use --force to overwrite.", :yellow
  end
end

#versionObject



118
119
120
121
# File 'lib/rfmt/cli.rb', line 118

def version
  say "rfmt #{Rfmt::VERSION}"
  say "Rust extension: #{Rfmt.rust_version}"
end