Module: Tempest::CLI

Defined in:
lib/tempest/cli.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.attach_store(session, store, identifier) ⇒ Object



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

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

.avatar_cache_dir(env) ⇒ Object



113
114
115
# File 'lib/tempest/cli.rb', line 113

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

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



101
102
103
# File 'lib/tempest/cli.rb', line 101

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

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



85
86
87
# File 'lib/tempest/cli.rb', line 85

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



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

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



89
90
91
# File 'lib/tempest/cli.rb', line 89

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



97
98
99
# File 'lib/tempest/cli.rb', line 97

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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tempest/cli.rb', line 49

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,
    )
  end
end

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



121
122
123
# File 'lib/tempest/cli.rb', line 121

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

.help_textObject



136
137
138
# File 'lib/tempest/cli.rb', line 136

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

.nil_if_empty(value) ⇒ Object



81
82
83
# File 'lib/tempest/cli.rb', line 81

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

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



117
118
119
# File 'lib/tempest/cli.rb', line 117

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



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

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.



77
78
79
# File 'lib/tempest/cli.rb', line 77

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)


93
94
95
# File 'lib/tempest/cli.rb', line 93

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

.timeline_store(env) ⇒ Object



109
110
111
# File 'lib/tempest/cli.rb', line 109

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

.watchdog_options(env) ⇒ Object



105
106
107
# File 'lib/tempest/cli.rb', line 105

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