Module: Tempest::CLI

Defined in:
lib/tempest/cli.rb

Constant Summary collapse

SUBCOMMANDS =
%w[tui post feed whoami follow].freeze
VALID_FEED_MODES =
Tempest::Commands::Tui::VALID_FEED_MODES

Class Method Summary collapse

Class Method Details

.attach_store(session, store, identifier) ⇒ Object



138
139
140
# File 'lib/tempest/cli.rb', line 138

def attach_store(session, store, identifier)
  Tempest::Commands::Tui.attach_store(session, store, identifier)
end

.avatar_cache_dir(env) ⇒ Object



119
120
121
# File 'lib/tempest/cli.rb', line 119

def avatar_cache_dir(env)
  Tempest::Commands::Tui.avatar_cache_dir(env)
end

.build_debug_logger(env, argv: []) ⇒ Object



107
108
109
# File 'lib/tempest/cli.rb', line 107

def build_debug_logger(env, argv: [])
  Tempest::Commands::Tui.build_debug_logger(env, argv: argv)
end

.build_reauth(env, stdout, stdin, session_factory) ⇒ Object



91
92
93
# File 'lib/tempest/cli.rb', line 91

def build_reauth(env, stdout, stdin, session_factory)
  Tempest::Commands::Tui.build_reauth(env, stdout, stdin, session_factory)
end

.build_subscription(mode:, session:, client:, handle_resolver: nil, stdout: nil) ⇒ Object



131
132
133
134
135
136
# File 'lib/tempest/cli.rb', line 131

def build_subscription(mode:, session:, client:, handle_resolver: nil, stdout: nil)
  Tempest::Commands::Tui.build_subscription(
    mode: mode, session: session, client: client,
    handle_resolver: handle_resolver, stdout: stdout,
  )
end

.create_with_2fa(config, env, stdout, stdin, session_factory) ⇒ Object



95
96
97
# File 'lib/tempest/cli.rb', line 95

def create_with_2fa(config, env, stdout, stdin, session_factory)
  Tempest::Commands::Tui.create_with_2fa(config, env, stdout, stdin, session_factory)
end

.cursor_store(env) ⇒ Object



103
104
105
# File 'lib/tempest/cli.rb', line 103

def cursor_store(env)
  Tempest::Commands::Tui.cursor_store(env)
end

.dispatch_subcommand(head, argv, env:, stdout:, stderr:, stdin:) ⇒ Object



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
# File 'lib/tempest/cli.rb', line 50

def dispatch_subcommand(head, argv, env:, stdout:, stderr:, stdin:)
  session = Tempest::Commands::Base.authenticate(env: env, stderr: stderr)
  return 3 if session.nil?
  client = Tempest::XRPCClient.new(session)
  case head
  when "whoami"
    Tempest::Commands::Whoami.call(
      argv: argv.drop(1), session: session,
      stdout: stdout, stderr: stderr,
    )
  when "post"
    Tempest::Commands::Post.call(
      argv: argv.drop(1), session: session, client: client,
      stdout: stdout, stderr: stderr, stdin: stdin,
    )
  when "feed"
    Tempest::Commands::Feed.call(
      argv: argv.drop(1), session: session, client: client,
      stdout: stdout, stderr: stderr,
    )
  when "follow"
    Tempest::Commands::Follow.call(
      argv: argv.drop(1), session: session, client: client,
      stdout: stdout, stderr: stderr,
    )
  end
end

.feed_mode(argv:, env: {}) ⇒ Object



127
128
129
# File 'lib/tempest/cli.rb', line 127

def feed_mode(argv:, env: {})
  Tempest::Commands::Tui.feed_mode(argv: argv, env: env)
end

.help_textObject



142
143
144
# File 'lib/tempest/cli.rb', line 142

def help_text
  Tempest::Commands::Tui.help_text
end

.nil_if_empty(value) ⇒ Object



87
88
89
# File 'lib/tempest/cli.rb', line 87

def nil_if_empty(value)
  Tempest::Commands::Tui.nil_if_empty(value)
end

.opener_for(env:, system_proc: Kernel.method(:system)) ⇒ Object



123
124
125
# File 'lib/tempest/cli.rb', line 123

def opener_for(env:, system_proc: Kernel.method(:system))
  Tempest::Commands::Tui.opener_for(env: env, system_proc: system_proc)
end

.run(argv: ARGV, env: ENV, stdout: $stdout, stderr: $stderr, stdin: $stdin, session_factory: Tempest::Session.method(:create), store: nil) ⇒ Object



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
# File 'lib/tempest/cli.rb', line 16

def run(argv: ARGV, env: ENV, stdout: $stdout, stderr: $stderr, stdin: $stdin,
        session_factory: Tempest::Session.method(:create),
        store: nil)
  if argv.include?("--version") || argv.include?("-v")
    stdout.puts "tempest #{Tempest::VERSION}"
    return 0
  end

  if argv.include?("--help") || argv.include?("-h")
    stdout.puts Tempest::Commands::Tui.help_text
    return 0
  end

  head = argv.first
  case
  when head.nil?, head.start_with?("-"), head == "tui"
    rest = (head == "tui") ? argv.drop(1) : argv
    Tempest::Commands::Tui.call(
      argv: rest, env: env, stdout: stdout, stderr: stderr, stdin: stdin,
      session_factory: session_factory, store: store,
    )
  when SUBCOMMANDS.include?(head)
    begin
      dispatch_subcommand(head, argv, env: env, stdout: stdout, stderr: stderr, stdin: stdin)
    rescue Tempest::Error, ArgumentError => e
      stderr.puts "error: #{e.message}"
      Tempest::Commands::Base.exit_code_for(e)
    end
  else
    stderr.puts "unknown command: #{head.inspect}"
    64
  end
end

.sign_in(env, stdout, stdin, session_factory, store:) ⇒ Object

Forwarding delegates — keep Tempest::CLI.* callable so existing tests do not need modification. All logic lives in Tempest::Commands::Tui.



83
84
85
# File 'lib/tempest/cli.rb', line 83

def (env, stdout, stdin, session_factory, store:)
  Tempest::Commands::Tui.(env, stdout, stdin, session_factory, store: store)
end

.stream_default_on?(argv, env) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/tempest/cli.rb', line 99

def stream_default_on?(argv, env)
  Tempest::Commands::Tui.stream_default_on?(argv, env)
end

.timeline_store(env) ⇒ Object



115
116
117
# File 'lib/tempest/cli.rb', line 115

def timeline_store(env)
  Tempest::Commands::Tui.timeline_store(env)
end

.watchdog_options(env) ⇒ Object



111
112
113
# File 'lib/tempest/cli.rb', line 111

def watchdog_options(env)
  Tempest::Commands::Tui.watchdog_options(env)
end