Module: WormCLI
- Defined in:
- lib/ruby-progress/cli/worm_cli.rb,
lib/ruby-progress/cli/worm_options.rb
Overview
Enhanced Worm CLI (extracted from bin/prg)
Defined Under Namespace
Modules: Options
Class Method Summary collapse
- .resolve_pid_file(options, name_key = :daemon_name) ⇒ Object
- .run ⇒ Object
- .run_daemon_mode(options) ⇒ Object
Class Method Details
.resolve_pid_file(options, name_key = :daemon_name) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ruby-progress/cli/worm_cli.rb', line 9 def self.resolve_pid_file(, name_key = :daemon_name) return [:pid_file] if [:pid_file] return "/tmp/ruby-progress/#{[name_key]}.pid" if [name_key] RubyProgress::Daemon.default_pid_file end |
.run ⇒ Object
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 |
# File 'lib/ruby-progress/cli/worm_cli.rb', line 17 def self.run trap('INT') do RubyProgress::Utils.show_cursor exit end = WormCLI::Options. if [:status] pid_file = resolve_pid_file(, :status_name) RubyProgress::Daemon.show_status(pid_file) exit elsif [:stop] pid_file = resolve_pid_file(, :stop_name) stop_msg = [:stop_error] || [:stop_success] is_error = ![:stop_error].nil? RubyProgress::Daemon.stop_daemon_by_pid_file( pid_file, message: stop_msg, checkmark: [:stop_checkmark], error: is_error ) exit elsif [:daemon] # Background without detaching so worm remains visible in current terminal PrgCLI.backgroundize run_daemon_mode() else progress = RubyProgress::Worm.new() if [:command] progress.run_with_command else progress.run_indefinitely end end end |
.run_daemon_mode(options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby-progress/cli/worm_cli.rb', line 56 def self.run_daemon_mode() pid_file = resolve_pid_file(, :daemon_name) FileUtils.mkdir_p(File.dirname(pid_file)) File.write(pid_file, Process.pid.to_s) progress = RubyProgress::Worm.new() begin progress.run_daemon_mode( success_message: [:success], show_checkmark: [:checkmark], control_message_file: RubyProgress::Daemon.(pid_file), icons: { success: [:success_icon], error: [:error_icon] } ) ensure FileUtils.rm_f(pid_file) end end |