terminalwire 0.1.9 → 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: a0eeaa4d2a6f23524e964bbd0fa0e507eca1415f591e71a565a47553411cf916
4
- data.tar.gz: 30d9f26ce42e8e5a4f301bd4d99ca5ead398554f737b0ffe693aa921fd8e8bb2
3
+ metadata.gz: 55ab6e5d0132726c5041fce03026f14963c2de4b60a2bc92cd2560b7f14890cf
4
+ data.tar.gz: b2f1d360f6135fddf2ab90ca5ad992f1e313ccd4de09cd8bca9314b6af0dbaac
5
5
  SHA512:
6
- metadata.gz: fb69226b00de7e49c73bcc1383aa5d31645cddd49d40c945131cb2e5b7c8c962a206c97127812278642c08371641e01a9a5d223f01c75551689d50a76257f691
7
- data.tar.gz: 62412bf6431e84e49895887ca879045038bc046470b32863056db319f4e69e0f8ecfdfac2e9141543d3ecf0dcbc5d3ba9821046828bd05a40653ab60512db0a5
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.
@@ -17,8 +17,6 @@ module Terminalwire
17
17
  @program_arguments = arguments
18
18
  @program_name = program_name
19
19
 
20
- FileUtils.mkdir_p entitlement.storage_path
21
-
22
20
  @resources = Resource::Handler.new do |it|
23
21
  it << Resource::STDOUT.new("stdout", @adapter, entitlement:)
24
22
  it << Resource::STDIN.new("stdin", @adapter, entitlement:)
@@ -39,7 +37,7 @@ module Terminalwire
39
37
  })
40
38
 
41
39
  loop do
42
- handle @adapter.recv
40
+ handle @adapter.read
43
41
  end
44
42
  end
45
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.9"
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.9
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