Module: RubyProgress::FillCLI

Defined in:
lib/ruby-progress/fill_cli.rb,
lib/ruby-progress/cli/fill_options.rb

Overview

CLI module for Fill command rubocop:disable Metrics/ClassLength

Defined Under Namespace

Modules: Options

Class Method Summary collapse

Class Method Details

.runvoid

This method returns an undefined value.

Entrypoint for the ‘prg fill` CLI. Parses options and dispatches to the matching behavior (auto-advance, command-run, daemon, report).



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ruby-progress/fill_cli.rb', line 19

def run
  trap('INT') do
    Utils.show_cursor
    exit
  end

  options = RubyProgress::FillCLI::Options.parse_cli_options

  # Handle basic output flags first
  if options[:help]
    puts RubyProgress::FillCLI::Options.help_text
    exit
  end

  if options[:version]
    puts "Fill version #{RubyProgress::FILL_VERSION}"
    exit
  end

  if options[:show_styles]
    show_fill_styles
    exit
  end

  # Handle daemon control first
  if options[:status] || options[:stop]
    pid_file = resolve_pid_file(options, :status_name)
    if options[:status]
      Daemon.show_status(pid_file)
    else
      Daemon.stop_daemon_by_pid_file(pid_file,
                                     message: options[:stop_success],
                                     checkmark: options[:stop_checkmark],
                                     error: !options[:stop_error].nil?)
    end
    exit
  end

  # Parse style option
  parsed_style = parse_fill_style(options[:style])

  if options[:daemon]
    # Resolve pid file and honor daemon-as/name
    pid_file = resolve_pid_file(options, :daemon_name)
    options[:pid_file] = pid_file

    # Background without detaching so progress bar remains visible in current terminal
    PrgCLI.backgroundize

    run_daemon_mode(options, parsed_style)
  elsif options[:current]
    show_current_percentage(options, parsed_style)
  elsif options[:report]
    show_progress_report(options, parsed_style)
  elsif options[:advance] || options[:complete] || options[:cancel]
    handle_progress_commands(options, parsed_style)
  else
    run_auto_advance_mode(options, parsed_style)
  end
end