Class: Legion::CLI::Tty
- Inherits:
-
Thor
- Object
- Thor
- Legion::CLI::Tty
- Defined in:
- lib/legion/cli/tty_command.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/legion/cli/tty_command.rb', line 9 def self.exit_on_failure? true end |
Instance Method Details
#interactive ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/cli/tty_command.rb', line 36 def interactive require_tty_gem config_dir = [:config_dir] || Legion::TTY::App::CONFIG_DIR app = Legion::TTY::App.new(config_dir: config_dir) app.start rescue Interrupt Legion::Logging.debug('TtyCommand#interactive interrupted by user') if defined?(Legion::Logging) app&.shutdown end |
#reset ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/legion/cli/tty_command.rb', line 48 def reset out = formatter config_dir = [:config_dir] || File.('~/.legionio/settings') identity = File.join(config_dir, 'identity.json') credentials = File.join(config_dir, 'credentials.json') unless [:confirm] out.warn('This will delete your saved identity and credentials.') out.warn('You will need to re-run onboarding.') require 'tty-prompt' prompt = ::TTY::Prompt.new return unless prompt.yes?('Continue?') end [identity, credentials].each do |path| if File.exist?(path) File.delete(path) out.success("Deleted #{File.basename(path)}") end end end |
#sessions ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/legion/cli/tty_command.rb', line 72 def sessions out = formatter require_tty_gem store = Legion::TTY::SessionStore.new list = store.list if list.empty? out.detail('No saved sessions.') return end list.each do |session| name = session[:name] count = session[:message_count] saved = session[:saved_at] || 'unknown' puts " #{name.ljust(30)} #{count} messages #{saved}" end end |
#version ⇒ Object
93 94 95 96 |
# File 'lib/legion/cli/tty_command.rb', line 93 def version require_tty_gem puts "legion-tty #{Legion::TTY::VERSION}" end |