Module: RippleCLI::Options

Defined in:
lib/ruby-progress/cli/ripple_options.rb

Overview

Option parsing extracted to its own file to reduce module size of RippleCLI.

Class Method Summary collapse

Class Method Details

.parse_cli_optionsHash

Parse CLI options for the ripple subcommand.

Returns:

  • (Hash)

    parsed options keyed by symbols



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
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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ruby-progress/cli/ripple_options.rb', line 12

def self.parse_cli_options
  options = {
    speed: :medium,
    direction: :bidirectional,
    styles: [],
    caps: false,
    command: nil,
    success_message: nil,
    fail_message: nil,
    complete_checkmark: false,
    output: :error,
    output_position: :above,
    output_lines: 3,
    message: nil
  }

  begin
    OptionParser.new do |opts|
      opts.banner = 'Usage: prg ripple [options] [STRING]'
      opts.separator ''
      opts.separator 'Animation Options:'

      opts.on('-s', '--speed SPEED', 'Animation speed (fast/medium/slow or f/m/s)') do |s|
        options[:speed] = case s.downcase
                          when /^f/ then :fast
                          when /^s/ then :slow
                          else :medium
                          end
      end

      opts.on('-m', '--message MESSAGE', 'Message to display (alternative to positional argument)') do |msg|
        options[:message] = msg
      end

      opts.on('--style STYLES', 'Animation styles (rainbow, inverse, caps - can be comma-separated)') do |styles|
        options[:styles] = styles.split(',').map(&:strip).map(&:to_sym)
      end

      opts.on('-d', '--direction DIRECTION', 'Animation direction (forward/bidirectional or f/b)') do |f|
        options[:format] = f =~ /^f/i ? :forward_only : :bidirectional
      end

      opts.on('--ends CHARS', 'Start/end characters (even number of chars, split in half)') do |chars|
        options[:ends] = chars
      end

      opts.separator ''
      opts.separator 'Command Execution:'

      opts.on('-c', '--command COMMAND', 'Run command during animation (optional)') do |command|
        options[:command] = command
      end

      opts.on('--output-position POSITION', 'Position to render captured output: above or below (default: above)') do |pos|
        options[:output_position] = pos.to_sym
      end

      opts.on('--output-lines N', Integer, 'Number of output lines to reserve for captured output (default: 3)') do |n|
        options[:output_lines] = n
      end

      opts.on('--success MESSAGE', 'Success message to display') do |msg|
        options[:success_message] = msg
      end

      opts.on('--success-icon ICON', 'Custom success icon to show with completion messages') do |ic|
        options[:success_icon] = ic
      end

      opts.on('--error-icon ICON', 'Custom error icon to show with failure messages') do |ic|
        options[:error_icon] = ic
      end

      opts.on('--error MESSAGE', 'Error message to display') do |msg|
        options[:fail_message] = msg
      end

      opts.on('--checkmark', 'Show checkmarks (✅ success, 🛑 failure)') do
        options[:complete_checkmark] = true
      end

      opts.on('--stdout', 'Output captured command result to STDOUT') do
        options[:output] = :stdout
      end

      opts.on('--stdout-live', 'Stream captured output to STDOUT as it arrives (non-blocking)') do
        options[:stdout_live] = true
      end

      opts.on('--quiet', 'Suppress all output') do
        options[:output] = :quiet
      end

      opts.separator ''
      opts.separator 'Daemon Mode:'

      opts.on('--daemon', 'Run in background daemon mode') do
        options[:daemon] = true
      end

      opts.on('--daemon-as NAME', 'Run in daemon mode with custom name (creates /tmp/ruby-progress/NAME.pid)') do |name|
        options[:daemon] = true
        options[:daemon_name] = name
      end

      opts.on('--pid-file FILE', 'Write process ID to file (default: /tmp/ruby-progress/progress.pid)') do |file|
        options[:pid_file] = file
      end

      opts.on('--stop', 'Stop daemon (uses default PID file unless --pid-file specified)') do
        options[:stop] = true
      end

      opts.on('--stop-id NAME', 'Stop daemon by name (automatically implies --stop)') do |name|
        options[:stop] = true
        options[:stop_name] = name
      end

      opts.on('--status', 'Show daemon status (running/not running)') do
        options[:status] = true
      end

      opts.on('--status-id NAME', 'Show daemon status by name') do |name|
        options[:status] = true
        options[:status_name] = name
      end

      opts.on('--stop-success MESSAGE', 'When stopping, show this success message') do |msg|
        options[:stop_success] = msg
      end
      opts.on('--stop-error MESSAGE', 'When stopping, show this error message') do |msg|
        options[:stop_error] = msg
      end
      opts.on('--stop-checkmark', 'When stopping, include a success/error checkmark') do
        options[:stop_checkmark] = true
      end

      opts.separator ''
      opts.separator 'Daemon notes:'
      opts.separator '  - Do not append &; prg detaches itself and returns immediately.'
      opts.separator '  - Use --daemon-as NAME for named daemons, or --stop-id/--status-id for named control.'

      opts.separator ''
      opts.separator 'General:'

      opts.on('--show-styles', 'Show available ripple styles with visual previews') do
        PrgCLI.show_ripple_styles
        exit
      end

      opts.on('--stop-all', 'Stop all prg ripple processes') do
        success = PrgCLI.stop_subcommand_processes('ripple')
        exit(success ? 0 : 1)
      end

      opts.on('-v', '--version', 'Show version') do
        puts "Ripple version #{RubyProgress::VERSION}"
        exit
      end

      opts.on('-h', '--help', 'Show this help') do
        puts opts
        exit
      end
    end.parse!
  rescue OptionParser::InvalidOption => e
    puts "Invalid option: #{e.args.first}"
    puts ''
    puts 'Usage: prg ripple [options] [STRING]'
    puts "Run 'prg ripple --help' for more information."
    exit 1
  end

  options
end