Class: Spill::CLI
- Inherits:
-
Object
- Object
- Spill::CLI
- Defined in:
- lib/spill/cli.rb
Class Method Summary collapse
- .ai_enabled?(options, stdout) ⇒ Boolean
- .build_report(args, options) ⇒ Object
- .build_report_and_summary(args, options, stdout, now) ⇒ Object
- .fetch_github(repo_map, window) ⇒ Object
- .run(argv, stdout: $stdout) ⇒ Object
Class Method Details
.ai_enabled?(options, stdout) ⇒ Boolean
44 45 46 |
# File 'lib/spill/cli.rb', line 44 def self.ai_enabled?(, stdout) [:ai] && Narrator.available? && stdout.respond_to?(:tty?) && stdout.tty? end |
.build_report(args, options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spill/cli.rb', line 48 def self.build_report(args, ) window = [:since] ? Window.parse([:since]) : Window.default repo_paths = RepoFinder.find(args.first || Dir.pwd) local = Collectors::LocalGit.new(repo_paths: repo_paths, author: [:author]) .collect(window: window) repo_map = RepoRemotes.slug_map(repo_paths) github = [: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 |
.build_report_and_summary(args, options, stdout, now) ⇒ Object
38 39 40 41 42 |
# File 'lib/spill/cli.rb', line 38 def self.build_report_and_summary(args, , stdout, now) report = build_report(args, ) summary = ai_enabled?(, stdout) ? Narrator.narrate(Renderer.render(report, color: false, now: now)) : nil [ report, summary ] end |
.fetch_github(repo_map, window) ⇒ Object
59 60 61 62 |
# File 'lib/spill/cli.rb', line 59 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 35 36 |
# File 'lib/spill/cli.rb', line 5 def self.run(argv, stdout: $stdout) = { github: true, ai: true } early_exit = false parser = OptionParser.new do |opts| opts. = "Usage: spill [ROOT] [options]" opts.on("--since EXPR", 'Window start: "yesterday", "3 days ago", "2026-07-01"') { |v| [:since] = v } opts.on("--author EMAIL", "Override the commit author for all repos") { |v| [:author] = v } opts.on("--no-github", "Skip the GitHub layer") { [:github] = false } opts.on("--no-ai", "Skip the AI summary") { [:ai] = 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 now = Time.now spinner_enabled = $stderr.tty? && stdout.respond_to?(:tty?) && stdout.tty? report, summary = Spinner.around(enabled: spinner_enabled) { build_report_and_summary(args, , stdout, now) } color = stdout.respond_to?(:tty?) && stdout.tty? && ENV["NO_COLOR"].nil? stdout.puts Renderer.render(report, color: color, now: now, summary: summary) 0 rescue OptionParser::ParseError, ArgumentError => e stdout.puts "spill: #{e.}" 0 end |