terminalwire 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cd319cc4f277520d44209f8317dabcb9113f1cb925f1ee6090e842ec007770b
4
- data.tar.gz: 1a7f2c111dfd9ac6576ae63d52b8342ebaff87e64c7a41202a8baf96cd786434
3
+ metadata.gz: 55ab6e5d0132726c5041fce03026f14963c2de4b60a2bc92cd2560b7f14890cf
4
+ data.tar.gz: b2f1d360f6135fddf2ab90ca5ad992f1e313ccd4de09cd8bca9314b6af0dbaac
5
5
  SHA512:
6
- metadata.gz: baf4b6ba33de5b317ce0fb52322b5b77c3bdc9cb7804245abf0b4969458024c24d58b08a45df88890d1bd902efdc61fbb7b78aef9a14be8ccde633eb10a7b2c8
7
- data.tar.gz: 3b553a00a66b9b6f26fbca86efa973058e6fca4ae3a13a5182772e3f2cfe83db8467ef49d0400e448fb55d70604f3207804aafcb550231fb0bd0decb06d494bd
6
+ metadata.gz: 5f003df286a23cff8e92c92d5372f81dc7cc0a915b1d32a6ba8c0bd5005a54395286b9a72aad2d6cc9856d0e6ba2c1622757a6bfbf8aba343885e55b42980227
7
+ data.tar.gz: eb480c644c568de7b6391a4e3310219fbf64869972eaeac7f0d4a7a6365b8fb644edd0193ae3920df604b3044b14fdfc09f05aa39a491be5d634ab084d8058d3
@@ -12,13 +12,13 @@ class ApplicationTerminal < Thor
12
12
  desc "login", "Login to your account"
13
13
  def login
14
14
  print "Email: "
15
- email = gets
15
+ email = gets.chomp
16
16
 
17
17
  print "Password: "
18
18
  password = getpass
19
19
 
20
20
  if self.current_user = User.authenticate(email, password)
21
- puts "Successfully logged in as #{user.email}."
21
+ puts "Successfully logged in as #{current_user.email}."
22
22
  else
23
23
  puts "Could not find a user with that email and password."
24
24
  end
@@ -27,7 +27,7 @@ class ApplicationTerminal < Thor
27
27
  desc "whoami", "Displays current user information."
28
28
  def whoami
29
29
  if self.current_user
30
- puts "Logged in as #{user.email}."
30
+ puts "Logged in as #{current_user.email}."
31
31
  else
32
32
  puts "Not logged in. Run `#{self.class.basename} login` to login."
33
33
  end
@@ -49,6 +49,6 @@ class ApplicationTerminal < Thor
49
49
  end
50
50
 
51
51
  def current_user
52
- @current_user ||= User.find(session.fetch("user_id"))
52
+ @current_user ||= User.find(session["user_id"])
53
53
  end
54
54
  end
@@ -17,7 +17,7 @@ module Terminalwire::Adapter
17
17
  @transport.write(packed_data)
18
18
  end
19
19
 
20
- def recv
20
+ def read
21
21
  logger.debug "Adapter: Reading"
22
22
  packed_data = @transport.read
23
23
  return nil if packed_data.nil?
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "io/console"
2
3
 
3
4
  module Terminalwire::Client::Resource
4
5
  # Dispatches messages from the Client::Handler to the appropriate resource.
@@ -37,7 +37,7 @@ module Terminalwire
37
37
  })
38
38
 
39
39
  loop do
40
- handle @adapter.recv
40
+ handle @adapter.read
41
41
  end
42
42
  end
43
43
 
@@ -12,7 +12,7 @@ module Terminalwire::Server
12
12
  parameters: parameters
13
13
  )
14
14
 
15
- response = @adapter.recv
15
+ response = @adapter.read
16
16
  case response.fetch(:status)
17
17
  when "success"
18
18
  response.fetch(:response)
@@ -53,13 +53,15 @@ module Terminalwire
53
53
  private
54
54
 
55
55
  def run(adapter)
56
- while message = adapter.recv
56
+ while message = adapter.read
57
57
  puts message
58
58
  end
59
59
  end
60
60
  end
61
61
 
62
62
  class Thor < WebSocket
63
+ Rails = ::Rails
64
+
63
65
  include Logging
64
66
 
65
67
  def initialize(cli_class)
@@ -70,13 +72,29 @@ module Terminalwire
70
72
  end
71
73
  end
72
74
 
75
+ def error_message
76
+ "An error occurred. Please try again."
77
+ end
78
+
73
79
  def run(adapter)
74
80
  logger.info "ThorServer: Running #{@cli_class.inspect}"
75
- while message = adapter.recv
81
+ while message = adapter.read
76
82
  case message
77
83
  in { event: "initialization", protocol:, program: { arguments: }, entitlement: }
78
- Terminalwire::Server::Context.new(adapter:, entitlement:) do |context|
84
+ context = Terminalwire::Server::Context.new(adapter:, entitlement:)
85
+
86
+ begin
79
87
  @cli_class.start(arguments, context:)
88
+ context.exit
89
+ rescue StandardError => e
90
+ if Rails.application.config.consider_all_requests_local
91
+ # Show the full error message with stack trace in development
92
+ context.stderr.puts "#{e.inspect}\n#{e.backtrace.join("\n")}"
93
+ else
94
+ # Show a generic message in production
95
+ context.stderr.puts error_message
96
+ end
97
+ context.exit 1
80
98
  end
81
99
  end
82
100
  end
@@ -93,7 +111,7 @@ module Terminalwire
93
111
  def run
94
112
  logger.info "Server Handler: Running"
95
113
  loop do
96
- message = @adapter.recv
114
+ message = @adapter.read
97
115
  case message
98
116
  in { event: "initialization", protocol:, program: { arguments: }, entitlement: }
99
117
  Context.new(adapter: @adapter) do |context|
@@ -35,7 +35,7 @@ module Terminalwire
35
35
  def_delegators :stdout,
36
36
  :puts, :print
37
37
  def_delegators :stdin,
38
- :gets
38
+ :gets, :getpass
39
39
 
40
40
  # Feels more naturual to call `client.files` etc. from
41
41
  # the serve since it's more apparent that it's a client.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminalwire
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminalwire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-28 00:00:00.000000000 Z
11
+ date: 2024-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket