Class: Spill::CLI

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

Class Method Summary collapse

Class Method Details

.build_report(args, options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/spill/cli.rb', line 36

def self.build_report(args, options)
  window = options[:since] ? Window.parse(options[:since]) : Window.default
  repo_paths = RepoFinder.find(args.first || Dir.pwd)
  local = Collectors::LocalGit.new(repo_paths: repo_paths, author: options[:author])
                              .collect(window: window)
  repo_map = RepoRemotes.slug_map(repo_paths)
  github = options[:github] ? fetch_github(repo_map, window) : []
  Report.build(local: local, github: github,
               repos: repo_paths.map { |path| File.basename(path) }, window: window, repo_map: repo_map)
end

.fetch_github(repo_map, window) ⇒ Object



47
48
49
50
# File 'lib/spill/cli.rb', line 47

def self.fetch_github(repo_map, window)
  scope = repo_map.keys.to_set
  Collectors::Github.new.collect(window: window, scope: scope)
end

.run(argv, stdout: $stdout) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spill/cli.rb', line 5

def self.run(argv, stdout: $stdout)
  options = { github: true }
  early_exit = false
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: spill [ROOT] [options]"
    opts.on("--since EXPR", 'Window start: "yesterday", "3 days ago", "2026-07-01"') { |v| options[:since] = v }
    opts.on("--author EMAIL", "Override the commit author for all repos") { |v| options[:author] = v }
    opts.on("--no-github", "Skip the GitHub layer") { options[:github] = false }
    opts.on("--version", "Print version") do
      stdout.puts Spill::VERSION
      early_exit = true
    end
    opts.on("-h", "--help", "Show this help") do
      stdout.puts opts
      early_exit = true
    end
  end

  args = parser.parse(argv)
  return 0 if early_exit

  spinner_enabled = $stderr.tty? && stdout.respond_to?(:tty?) && stdout.tty?
  report = Spinner.around(enabled: spinner_enabled) { build_report(args, options) }
  color = stdout.respond_to?(:tty?) && stdout.tty? && ENV["NO_COLOR"].nil?
  stdout.puts Renderer.render(report, color: color)
  0
rescue OptionParser::ParseError, ArgumentError => e
  stdout.puts "spill: #{e.message}"
  0
end