Module: Tempest::CLI
- Defined in:
- lib/tempest/cli.rb
Constant Summary collapse
- SUBCOMMANDS =
%w[tui post feed whoami follow accounts login].freeze
- VALID_FEED_MODES =
Tempest::Commands::Tui::VALID_FEED_MODES
Class Method Summary collapse
- .attach_store(session, store, identifier) ⇒ Object
- .avatar_cache_dir(env) ⇒ Object
- .build_debug_logger(env, argv: []) ⇒ Object
- .build_reauth(env, stdout, stdin, session_factory) ⇒ Object
-
.build_subcommand_logger(env) ⇒ Object
Build the info-level logger used by non-TUI subcommands so that account/login/migration events still reach info.log.
- .build_subscription(mode:, session:, client:, handle_resolver: nil, stdout: nil) ⇒ Object
- .create_with_2fa(config, env, stdout, stdin, session_factory) ⇒ Object
- .cursor_store(env) ⇒ Object
- .dispatch_subcommand(head, argv, env:, stdout:, stderr:, stdin:, user: nil, logger: nil) ⇒ Object
-
.extract_user(argv) ⇒ Object
Pulls ‘–user <name>` / `–user=<name>` out of argv and returns `[user_or_nil, remaining_argv]`.
- .feed_mode(argv:, env: {}) ⇒ Object
- .help_text ⇒ Object
- .nil_if_empty(value) ⇒ Object
- .opener_for(env:, system_proc: Kernel.method(:system)) ⇒ Object
- .run(argv: ARGV, env: ENV, stdout: $stdout, stderr: $stderr, stdin: $stdin, session_factory: Tempest::Session.method(:create), store: nil) ⇒ Object
-
.sign_in(env, stdout, stdin, session_factory, store:) ⇒ Object
Forwarding delegates — keep Tempest::CLI.* callable so existing tests do not need modification.
- .stream_default_on?(argv, env) ⇒ Boolean
- .timeline_store(env) ⇒ Object
- .watchdog_options(env) ⇒ Object
Class Method Details
.attach_store(session, store, identifier) ⇒ Object
220 221 222 |
# File 'lib/tempest/cli.rb', line 220 def attach_store(session, store, identifier) Tempest::Commands::Tui.attach_store(session, store, identifier) end |
.avatar_cache_dir(env) ⇒ Object
201 202 203 |
# File 'lib/tempest/cli.rb', line 201 def avatar_cache_dir(env) Tempest::Commands::Tui.avatar_cache_dir(env) end |
.build_debug_logger(env, argv: []) ⇒ Object
189 190 191 |
# File 'lib/tempest/cli.rb', line 189 def build_debug_logger(env, argv: []) Tempest::Commands::Tui.build_debug_logger(env, argv: argv) end |
.build_reauth(env, stdout, stdin, session_factory) ⇒ Object
173 174 175 |
# File 'lib/tempest/cli.rb', line 173 def build_reauth(env, stdout, stdin, session_factory) Tempest::Commands::Tui.build_reauth(env, stdout, stdin, session_factory) end |
.build_subcommand_logger(env) ⇒ Object
Build the info-level logger used by non-TUI subcommands so that account/login/migration events still reach info.log. Always non-verbose (no ‘debug:` flag), distinct from the TUI’s ‘–debug` channel.
126 127 128 |
# File 'lib/tempest/cli.rb', line 126 def build_subcommand_logger(env) Tempest::DebugLog.build(env: env, debug: false) end |
.build_subscription(mode:, session:, client:, handle_resolver: nil, stdout: nil) ⇒ Object
213 214 215 216 217 218 |
# File 'lib/tempest/cli.rb', line 213 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
177 178 179 |
# File 'lib/tempest/cli.rb', line 177 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
185 186 187 |
# File 'lib/tempest/cli.rb', line 185 def cursor_store(env) Tempest::Commands::Tui.cursor_store(env) end |
.dispatch_subcommand(head, argv, env:, stdout:, stderr:, stdin:, user: nil, logger: nil) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/tempest/cli.rb', line 130 def dispatch_subcommand(head, argv, env:, stdout:, stderr:, stdin:, user: nil, logger: nil) session, code = Tempest::Commands::Base.authenticate_with_code( env: env, stderr: stderr, user: user, logger: logger, ) return code 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 |
.extract_user(argv) ⇒ Object
Pulls ‘–user <name>` / `–user=<name>` out of argv and returns `[user_or_nil, remaining_argv]`. Raises ArgumentError when the flag is present but the value is missing or empty. Multiple occurrences: last one wins.
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 24 def extract_user(argv) user = nil remaining = [] i = 0 while i < argv.length arg = argv[i] if arg == "--user" nxt = argv[i + 1] if nxt.nil? || nxt.empty? || nxt.start_with?("-") raise ArgumentError, "--user requires a value" end user = nxt i += 2 elsif arg.start_with?("--user=") value = arg["--user=".length..] raise ArgumentError, "--user requires a value" if value.nil? || value.empty? user = value i += 1 else remaining << arg i += 1 end end [user, remaining] end |
.feed_mode(argv:, env: {}) ⇒ Object
209 210 211 |
# File 'lib/tempest/cli.rb', line 209 def feed_mode(argv:, env: {}) Tempest::Commands::Tui.feed_mode(argv: argv, env: env) end |
.help_text ⇒ Object
224 225 226 |
# File 'lib/tempest/cli.rb', line 224 def help_text Tempest::Commands::Tui.help_text end |
.nil_if_empty(value) ⇒ Object
169 170 171 |
# File 'lib/tempest/cli.rb', line 169 def nil_if_empty(value) Tempest::Commands::Tui.nil_if_empty(value) end |
.opener_for(env:, system_proc: Kernel.method(:system)) ⇒ Object
205 206 207 |
# File 'lib/tempest/cli.rb', line 205 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
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/tempest/cli.rb', line 50 def run(argv: ARGV, env: ENV, stdout: $stdout, stderr: $stderr, stdin: $stdin, session_factory: Tempest::Session.method(:create), store: nil) begin user, argv = extract_user(argv) rescue ArgumentError => e stderr.puts "error: #{e.}" return 64 end 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" Tempest::DeprecatedEnvs.warn_if_set(env: env, stderr: stderr) 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, user: user, ) when head == "login" if user stderr.puts "error: --user is not supported for `login`" return 64 end logger = build_subcommand_logger(env) begin Tempest::Commands::Login.call( argv: argv.drop(1), env: env, stdout: stdout, stderr: stderr, stdin: stdin, session_factory: session_factory, logger: logger, ) rescue Tempest::Error, ArgumentError => e stderr.puts "error: #{e.}" Tempest::Commands::Base.exit_code_for(e) end when head == "accounts" if user stderr.puts "error: --user is not supported for `accounts`" return 64 end logger = build_subcommand_logger(env) begin Tempest::Commands::Accounts.call( argv: argv.drop(1), env: env, stdout: stdout, stderr: stderr, logger: logger, ) rescue Tempest::Error, ArgumentError => e stderr.puts "error: #{e.}" Tempest::Commands::Base.exit_code_for(e) end when SUBCOMMANDS.include?(head) Tempest::DeprecatedEnvs.warn_if_set(env: env, stderr: stderr) logger = build_subcommand_logger(env) begin dispatch_subcommand(head, argv, env: env, stdout: stdout, stderr: stderr, stdin: stdin, user: user, logger: logger) rescue Tempest::Error, ArgumentError => e stderr.puts "error: #{e.}" 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.
165 166 167 |
# File 'lib/tempest/cli.rb', line 165 def sign_in(env, stdout, stdin, session_factory, store:) Tempest::Commands::Tui.sign_in(env, stdout, stdin, session_factory, store: store) end |
.stream_default_on?(argv, env) ⇒ Boolean
181 182 183 |
# File 'lib/tempest/cli.rb', line 181 def stream_default_on?(argv, env) Tempest::Commands::Tui.stream_default_on?(argv, env) end |
.timeline_store(env) ⇒ Object
197 198 199 |
# File 'lib/tempest/cli.rb', line 197 def timeline_store(env) Tempest::Commands::Tui.timeline_store(env) end |